Skip to content

ID Lookup Functionality

The Logic.Monitor PowerShell module includes automatic ID lookup capabilities that make it easier to work with resources using names instead of IDs. While this is convenient for interactive use, there are important considerations for automation and scripting.

How ID Lookup Works

Many commands support both ID and Name parameters. When using names, the module automatically:

  1. Performs a GET request to find the resource ID
  2. Uses the retrieved ID for the actual operation
Terminal window
# Using name (performs automatic lookup)
Remove-LMDevice -Name "web-server-01"
# Behind the scenes, this is equivalent to:
$deviceId = (Get-LMDevice -Name "web-server-01").id
Remove-LMDevice -Id $deviceId

Supported Parameters

Different commands support various lookup parameters:

Device Commands

  • Name (system.hostname)
  • DisplayName (displayName)
Terminal window
# These all refer to the same device
Set-LMDevice -Name "server01.domain.com" -Properties @{location = "NYC"}
Set-LMDevice -DisplayName "Production Web Server" -Properties @{location = "NYC"}
Set-LMDevice -Id 123 -Properties @{location = "NYC"}

Group Commands

  • Name (group name)
  • FullPath (complete group path)
Terminal window
# Different ways to reference the same group
Remove-LMDeviceGroup -Name "Web Servers"
Remove-LMDeviceGroup -FullPath "Production/Web Servers"
Remove-LMDeviceGroup -Id 456

Best Practices

Interactive Use

When working interactively, using names is convenient:

Terminal window
# Good for interactive use
Get-LMDevice -DisplayName "web*" | Remove-LMDevice

Automation Scripts

For automation, use IDs to avoid extra API calls and potential rate limiting:

Terminal window
# Better for automation - cache IDs
$deviceIds = Get-LMDevice -Filter "displayName -contains 'web'" |
Select-Object -ExpandProperty id
foreach ($id in $deviceIds) {
Remove-LMDevice -Id $id
}

Bulk Operations

When performing bulk operations, collect IDs first:

Terminal window
# Less efficient - performs lookup for each device
Get-LMDevice -Filter "status -eq 'dead'" |
ForEach-Object { Remove-LMDevice -Name $_.name }
# More efficient - uses cached IDs
$devices = Get-LMDevice -Filter "status -eq 'dead'"
$devices | Remove-LMDevice -Id { $_.id }

Rate Limiting Considerations

Each name lookup requires an additional API call, which can impact rate limits:

Terminal window
# May hit rate limits - performs lookup for each device
foreach ($name in $deviceNames) {
Set-LMDevice -Name $name -Properties @{updated = $true}
}
# Better approach - single lookup, then use IDs
$devices = Get-LMDevice -Filter "name -in $($deviceNames -join ',')"
foreach ($device in $devices) {
Set-LMDevice -Id $device.id -Properties @{updated = $true}
}

Lookup Performance Example

Here’s a comparison of operations with and without ID caching:

Terminal window
# Without ID caching (10 API calls)
1..10 | ForEach-Object {
Set-LMDevice -Name "server-$_" -Properties @{updated = $true}
}
# With ID caching (2 API calls)
$devices = Get-LMDevice -Filter "name -contains 'server-'"
$devices | ForEach-Object {
Set-LMDevice -Id $_.id -Properties @{updated = $true}
}

Error Handling

The module includes built-in error handling for lookups:

Terminal window
# Handles non-existent resources
try {
Remove-LMDevice -Name "non-existent-server" -ErrorAction Stop
}
catch {
Write-Error "Device not found: $_"
}
# Handle ambiguous names
try {
Set-LMDevice -DisplayName "web" -Properties @{updated = $true}
}
catch {
Write-Error "Multiple devices found matching 'web'. Please use a more specific name or ID."
}

Remember:

  • Use names for interactive work and one-off operations
  • Use IDs for scripts and automation
  • Cache IDs when performing bulk operations
  • Consider rate limits when designing automation scripts