Request Details
- HTTP method (GET, POST, PATCH, DELETE)
- Complete endpoint URL
- Query parameters
- Portal information
The Logic.Monitor PowerShell module includes several built-in features to help you debug and test commands before executing them. This guide covers the main debugging tools available.
The -Debug parameter provides detailed information about API requests to help troubleshoot issues.
Request Details
Headers
Payload
# Debug a GET requestGet-LMDevice -Name "prod-web01" -Debug
# Output:# DEBUG: ============ LogicMonitor API Debug Info ==============# DEBUG: Command: Get-LMDevice | Method: GET | Timestamp: 2024-01-15 10:30:45.123# DEBUG: Parameters: Name: prod-web01# DEBUG: Endpoint: /device/devices?filter=name:"prod-web01"# DEBUG: Portal: company.logicmonitor.com# DEBUG: Headers: Authorization: LMv1... | Content-Type: application/json | X-Version: 3# DEBUG: Request Payload: None (GET request)# DEBUG: ========================================================# Debug a POST requestNew-LMDevice -Name "server01" -DisplayName "Test Server" -PreferredCollectorId 5 -Debug
# Output:# DEBUG: ============ LogicMonitor API Debug Info ==============# DEBUG: Command: New-LMDevice | Method: POST | Timestamp: 2024-01-15 10:31:22.456# DEBUG: Parameters: Name: server01 | DisplayName: Test Server | PreferredCollectorId: 5# DEBUG: Endpoint: /device/devices# DEBUG: Portal: company.logicmonitor.com# DEBUG: Headers: Authorization: LMv1... | Content-Type: application/json | X-Version: 3# DEBUG: Request Payload:# DEBUG: {# DEBUG: "name": "server01",# DEBUG: "displayName": "Test Server",# DEBUG: "preferredCollectorId": 5,# DEBUG: "deviceType": 0# DEBUG: }# DEBUG: ========================================================# Debug a PATCH requestSet-LMDevice -Id 123 -Properties @{environment="prod"} -Debug
# Output shows the complete JSON payload including the custom properties array# DEBUG: Request Payload:# DEBUG: {# DEBUG: "customProperties": [# DEBUG: {# DEBUG: "name": "environment",# DEBUG: "value": "prod"# DEBUG: }# DEBUG: ]# DEBUG: }The -WhatIf parameter shows what would happen if you ran the command without actually executing it. This is available on all commands that modify resources (New-, Set-, Remove-).
# See what devices would be removed without actually removing themGet-LMDevice -Filter "name -contains 'test'" | Remove-LMDevice -WhatIf
# Output:# What if: Would remove device 'test-server-01' (ID: 123)# What if: Would remove device 'test-server-02' (ID: 124)
# Preview property changesSet-LMDevice -Id 123 -Properties @{ "environment" = "production" "team" = "platform"} -WhatIf
# Output:# What if: Would update properties for device 'prod-web01' (ID: 123)This is especially useful for:
The module includes built-in error handling. Here’s how to properly handle errors in your scripts:
# Using try/catch blockstry { New-LMDevice -Name "test-server" -DisplayName "Test Server" -ErrorAction Stop}catch { Write-Error "Failed to create device: $_"}
# Using -ErrorActionGet-LMDevice -Name "non-existent" -ErrorAction SilentlyContinueif (!$?) { Write-Warning "Device not found"}# Set debug preference for entire session$DebugPreference = "Continue"
# All commands will now show debug outputGet-LMDevice -Name "server01"Set-LMDevice -Id 123 -Properties @{test="value"}
# Reset when done$DebugPreference = "SilentlyContinue"# Debug shows complete request structureInvoke-LMAPIRequest ` -ResourcePath "/device/devices" ` -Method POST ` -Data @{ name = "test-server" displayName = "Test" preferredCollectorId = 5 } ` -Debug# Check if you're connectedif (-not $Script:LMAuth.Valid) { Write-Warning "Not connected to LogicMonitor" Connect-LMAccount -AccessId $id -AccessKey $key -AccountName "portal"}
# Verify portal connection$Script:LMAuth
# Debug authentication issuesConnect-LMAccount -AccessId $id -AccessKey $key -AccountName "portal" -Debug# Enable verbose and debug output$VerbosePreference = "Continue"$DebugPreference = "Continue"
# Run problematic commandGet-LMDevice -Name "problem-device"
# Check the debug output for:# - Correct endpoint URL# - Proper authentication headers# - Valid query parameters# - Expected payload format# The module automatically retries on rate limits# Debug output will show retry attempts:
Get-LMDevice -Debug
# Output may show:# VERBOSE: Request failed (RateLimit), retrying (attempt 1 of 3)
# For bulk operations, add delaysforeach ($device in $devices) { Set-LMDevice -Id $device.id -Properties @{updated=$true} Start-Sleep -Milliseconds 500 # Avoid rate limits}# Test filter syntax before using in automation$filter = "displayName -contains 'prod'"
# Preview resultsGet-LMDevice -Filter $filter | Select-Object id, name, displayName | Format-Table
# Use -Debug to see the actual API filterGet-LMDevice -Filter $filter -Debug
# Check the Endpoint line to see translated filter:# DEBUG: Endpoint: /device/devices?filter=displayName~"prod"✅ DO
-WhatIf before bulk operations-Debug when troubleshooting❌ DON'T
-WhatIf for destructive operations# 1. Test filter first$filter = "status -eq 'dead'"Get-LMDevice -Filter $filter | Select-Object id, name | Format-Table
# 2. Preview changes with -WhatIfGet-LMDevice -Filter $filter | Remove-LMDevice -WhatIf
# 3. Test on single item with -DebugGet-LMDevice -Filter $filter | Select-Object -First 1 | Remove-LMDevice -Debug
# 4. If all looks good, proceed with actual operationGet-LMDevice -Filter $filter | Remove-LMDevice -Confirm:$false-Debug to learn payload formats