Code Snippets Library
This library contains practical code snippets and examples for common LogicMonitor automation tasks. Each snippet includes detailed examples and the full source code for reference.
Bulk Import Operations
Section titled “Bulk Import Operations”Import Devices from CSV
Section titled “Import Devices from CSV”Note: This functionality is now part of the core module, implemented at the request of customers. See the official documentation for full details.
See the full documentation: Import-LMDevicesFromCSV
Usage examples:
# Generate a sample CSV templateImport-LMDevicesFromCSV -GenerateExampleCSV
# Import devices from CSV with specific collectorImport-LMDevicesFromCSV -FilePath "devices.csv" -CollectorId 1 -PassThru
# Import devices with auto-balanced collector groupImport-LMDevicesFromCSV -FilePath "devices.csv" -AutoBalancedCollectorGroupId 2This command imports devices from a CSV file into LogicMonitor. See the documentation for CSV format and advanced options.
Import Device Groups from CSV
Section titled “Import Device Groups from CSV”Note: This functionality is now part of the core module, implemented at the request of customers. See the official documentation for full details.
See the full documentation: Import-LMDeviceGroupsFromCSV
Usage examples:
# Generate a sample CSV templateImport-LMDeviceGroupsFromCSV -GenerateExampleCSV
# Import device groups from CSVImport-LMDeviceGroupsFromCSV -FilePath "groups.csv" -PassThruThis command imports device groups and their hierarchies from a CSV file. See the documentation for CSV format and advanced options.
Device Management
Section titled “Device Management”Deduplicate Devices
Section titled “Deduplicate Devices”Note: This functionality is now part of the core module, implemented at the request of customers. See the official documentation for full details.
See the full documentation: Invoke-LMDeviceDedupe
Usage examples:
# List potential duplicate devicesInvoke-LMDeviceDedupe -ListDuplicates -DeviceGroupId 8
# Remove duplicate devicesInvoke-LMDeviceDedupe -RemoveDuplicates -DeviceGroupId 8
# Exclude specific IPs or device types from deduplicationInvoke-LMDeviceDedupe -ListDuplicates -IpExclusionList @("10.0.0.1","10.0.0.2") -ExcludeDeviceType @(8,9)This command helps identify and remove duplicate devices in your LogicMonitor portal. See the documentation for exclusion options and removal.
Copy Device Properties to Groups
Section titled “Copy Device Properties to Groups”Note: This functionality is now part of the core module, implemented at the request of customers. See the official documentation for full details.
See the full documentation: Copy-LMDevicePropertyToGroup
Usage examples:
# Copy specific properties from a device to groupsCopy-LMDevicePropertyToGroup -SourceDeviceId 123 -TargetGroupId 456,457 -PropertyNames "location","department"
# Copy properties from random device in source groupCopy-LMDevicePropertyToGroup -SourceGroupId 789 -TargetGroupId 456 -PropertyNames "location" -PassThru
# Copy multiple properties to multiple groups$props = @("location", "environment", "team")$targetGroups = @(456, 457, 458)Copy-LMDevicePropertyToGroup -SourceDeviceId 123 -TargetGroupId $targetGroups -PropertyNames $propsThis command copies properties from a source device to one or more device groups. See the documentation for all options.
Copy Device Properties to Devices
Section titled “Copy Device Properties to Devices”Note: This functionality is now part of the core module, implemented at the request of customers. See the official documentation for full details.
See the full documentation: Copy-LMDevicePropertyToDevice
Usage examples:
# Copy specific properties from a device to devicesCopy-LMDevicePropertyToDevice -SourceDeviceId 123 -TargetDeviceId 456 -PropertyNames "location","department"
# Copy properties from random device in source groupCopy-LMDevicePropertyToDevice -SourceGroupId 789 -TargetDeviceId 456,457 -PropertyNames "location" -PassThru
# Copy multiple properties to multiple devices$props = @("location", "environment", "team")$targetDevices = @(456, 457, 458)Copy-LMDevicePropertyToDevice -SourceDeviceId 123 -TargetDeviceId $targetDevices -PropertyNames $propsThis command copies properties from a source device to one or more target devices. See the documentation for all options.
Dashboard Management
Section titled “Dashboard Management”Find Dashboard Widgets
Section titled “Find Dashboard Widgets”Note: This functionality is now part of the core module, implemented at the request of customers. See the official documentation for full details.
See the full documentation: Find-LMDashboardWidgets
Usage examples:
# Find widgets using specific datasourcesFind-LMDashboardWidgets -DatasourceNames "SNMP_Network_Interfaces"
# Search multiple datasources$datasources = @( "SNMP_Network_Interfaces", "VMware_vCenter_VM_Performance")Find-LMDashboardWidgets -DatasourceNames $datasources
# Search in specific dashboard group pathFind-LMDashboardWidgets -DatasourceNames "Windows_Performance" -GroupPathSearchString "*/Production/*"
# Pipe datasource names"SNMP_Network_Interfaces","Windows_Performance" | Find-LMDashboardWidgetsThis command helps locate dashboard widgets that use specific datasources. See the documentation for advanced search options.