Pipeline Support
Pipeline Support
Many Logic.Monitor cmdlets support pipeline input, allowing you to chain commands together for more efficient automation. This guide demonstrates common pipeline patterns and examples.
Basic Pipeline Examples
Device Management
# Get all devices and update their propertiesGet-LMDevice -Filter "displayName -contains 'web'" | Set-LMDevice -Properties @{"environment" = "production"}
# Remove multiple devicesGet-LMDevice -Filter "status -eq 'dead'" | Remove-LMDevice -Confirm:$false
Alert Management
# Acknowledge multiple alertsGet-LMAlert -Severity 'Critical' | New-LMAlertAck -Note "Investigating performance issues"
# Add notes to alertsGet-LMAlert -Filter "resourceTemplateName -eq 'VMware'" | New-LMAlertNote -Note "Escalated to VMware team"
Property Management
# Copy properties between devicesGet-LMDevice -Name "template-server" | Select-Object -ExpandProperty customProperties | Set-LMDevice -Id 123 -Properties $_
# Update multiple device groupsGet-LMDeviceGroup -Filter "parentId -eq 0" | Set-LMDeviceGroup -Properties @{"monitoring_level" = "premium"}
Advanced Pipeline Scenarios
Multi-Stage Pipelines
# Find and update devices, then add them to a groupGet-LMDevice -Filter "displayName -contains 'web'" | Set-LMDevice -Properties @{"environment" = "production"} | Add-LMDeviceToGroup -GroupName "Production Web Servers"
# Process alerts with multiple actionsGet-LMAlert -Filter "severity -eq 'Critical'" | ForEach-Object { $_ | New-LMAlertAck -Note "Auto-acknowledged" $_ | New-LMAlertNote -Note "Escalating to on-call team" $_ | New-LMAlertEscalation }
Filtering and Processing
# Process specific propertiesGet-LMDevice | Where-Object { $_.properties.environment -eq "production" } | ForEach-Object { $_ | Set-LMDevice -Properties @{ "sla_tier" = "high" "backup_enabled" = "true" } }
# Batch processing with Select-ObjectGet-LMAlert -Filter "ackTime -eq '$null'" | Select-Object -First 10 | New-LMAlertAck -Note "Batch acknowledgment"
Best Practices
-
Use ValueFromPipelineByPropertyName
Terminal window # Commands that accept pipeline input by property nameGet-LMDevice | Select-Object id, name | Remove-LMDevice -
Handle Large Datasets
Terminal window # Process items in batchesGet-LMDevice |Select-Object -First 1000 |ForEach-Object -Parallel {$_ | Set-LMDevice -Properties @{"updated" = "true"}} -ThrottleLimit 5 -
Error Handling in Pipelines
Terminal window Get-LMDevice -Filter "status -eq 'dead'" |ForEach-Object {try {$_ | Remove-LMDevice -ErrorAction StopWrite-Host "Removed device: $($_.displayName)"}catch {Write-Error "Failed to remove $($_.displayName): $_"}}
Cmdlets Supporting Pipeline Input
Here are some commonly used cmdlets that support pipeline input:
-
Device Management
Set-LMDevice
Remove-LMDevice
Add-LMDeviceToGroup
-
Alert Management
New-LMAlertAck
New-LMAlertNote
New-LMAlertEscalation
-
Group Management
Set-LMDeviceGroup
Remove-LMDeviceGroup
Copy-LMDevicePropertyToGroup
To check if a cmdlet supports pipeline input, use:
Get-Help Logic.Monitor -Full | Select-Object -ExpandProperty parameters | Where-Object { $_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName }