Data Extraction
Export Device Data
Section titled “Export Device Data”# Export device properties to CSVGet-LMDevice | Select-Object name, displayName, hostGroupIds, properties | Export-Csv -Path "device_properties.csv" -NoTypeInformation
# Export device instance data$devices = Get-LMDevice -Filter "displayName -contains 'prod'"foreach ($device in $devices) { $data = Get-LMDeviceData -Id $device.id -StartDate (Get-Date).AddDays(-7) $data | Export-Csv -Path "device_$($device.id)_data.csv" -NoTypeInformation}Export Alert Data
Section titled “Export Alert Data”# Export critical alerts from last 24 hoursGet-LMAlert -Severity Warning -StartDate $(Get-Date).AddDays(-1) | Export-Csv -Path "critical_alerts.csv" -NoTypeInformation
# Export acknowledged alerts with notes$alerts = Get-LMAlert -Filter "ack -ne '$true'"foreach ($alert in $alerts) { $notes = Get-LMAlertNote -Id $alert.id [PSCustomObject]@{ AlertId = $alert.id Resource = $alert.resourceTemplateName Notes = $notes.note -join "; " }} | Export-Csv -Path "alert_notes.csv" -NoTypeInformationExtract Device Group Custom Properties
Section titled “Extract Device Group Custom Properties”Extract specific custom properties from device groups, including checking parent groups for inherited properties:
# Get all device groups and extract specific custom properties$deviceGroups = Get-LMDeviceGroup
# Create a lookup dictionary for quick parent group access$groupLookup = @{}foreach ($group in $deviceGroups) { $groupLookup[$group.id] = $group}
# Define the custom property keys to extract$dataPointNameKey = "nre_filter.application-delivery.gslb.CPU.dataPointName"$datasourceNameKey = "nre_filter.application-delivery.gslb.CPU.datasource_name"
# Function to check parent chain for a custom propertyfunction Get-InheritedProperty { param( [Object]$CurrentGroup, [Hashtable]$GroupLookup, [String]$PropertyKey )
# Check current group's customProperties first if ($CurrentGroup.customProperties) { $prop = $CurrentGroup.customProperties | Where-Object { $_.name -eq $PropertyKey } if ($prop) { return @{ Value = $prop.value; Source = "Direct" } } }
# Traverse up the parent chain $parentId = $CurrentGroup.parentId while ($parentId -ne 0 -and $GroupLookup.ContainsKey($parentId)) { $parentGroup = $GroupLookup[$parentId]
if ($parentGroup.customProperties) { $prop = $parentGroup.customProperties | Where-Object { $_.name -eq $PropertyKey } if ($prop) { return @{ Value = $prop.value; Source = "Inherited" } } }
$parentId = $parentGroup.parentId }
return @{ Value = "N/A"; Source = "N/A" }}
# Process each device group$results = $deviceGroups | ForEach-Object { $group = $_
# Get properties (checking direct first, then parent chain) $dataPointNameResult = Get-InheritedProperty -CurrentGroup $group -GroupLookup $groupLookup -PropertyKey $dataPointNameKey $datasourceNameResult = Get-InheritedProperty -CurrentGroup $group -GroupLookup $groupLookup -PropertyKey $datasourceNameKey
# Create output object with all requested properties [PSCustomObject]@{ id = $group.id name = $group.name parentId = $group.parentId dataPointName = $dataPointNameResult.Value dataPointNameSource = $dataPointNameResult.Source datasourceName = $datasourceNameResult.Value datasourceNameSource = $datasourceNameResult.Source numOfHosts = $group.numOfHosts numOfAWSDevices = $group.numOfAWSDevices numOfAzureDevices = $group.numOfAzureDevices numOfGcpDevices = $group.numOfGcpDevices numOfOciDevices = $group.numOfOciDevices numOfKubernetesDevices = $group.numOfKubernetesDevices numOfDirectDevices = $group.numOfDirectDevices numOfDirectSubGroups = $group.numOfDirectSubGroups }}
# Output results$results | Format-Table -AutoSize# Or export to CSV: $results | Export-Csv -Path "device-groups-custom-props.csv" -NoTypeInformationThis example extracts specific custom properties from all device groups, checking both direct properties and inherited properties from parent groups. The output includes the property values and their source (Direct, Inherited, or N/A).