Skip to content

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

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:

Terminal window
# Generate a sample CSV template
Import-LMDevicesFromCSV -GenerateExampleCSV
# Import devices from CSV with specific collector
Import-LMDevicesFromCSV -FilePath "devices.csv" -CollectorId 1 -PassThru
# Import devices with auto-balanced collector group
Import-LMDevicesFromCSV -FilePath "devices.csv" -AutoBalancedCollectorGroupId 2

This command imports devices from a CSV file into LogicMonitor. See the documentation for CSV format and advanced options.

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:

Terminal window
# Generate a sample CSV template
Import-LMDeviceGroupsFromCSV -GenerateExampleCSV
# Import device groups from CSV
Import-LMDeviceGroupsFromCSV -FilePath "groups.csv" -PassThru

This command imports device groups and their hierarchies from a CSV file. See the documentation for CSV format and advanced options.

Device Management

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:

Terminal window
# List potential duplicate devices
Invoke-LMDeviceDedupe -ListDuplicates -DeviceGroupId 8
# Remove duplicate devices
Invoke-LMDeviceDedupe -RemoveDuplicates -DeviceGroupId 8
# Exclude specific IPs or device types from deduplication
Invoke-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

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:

Terminal window
# Copy specific properties from a device to groups
Copy-LMDevicePropertyToGroup -SourceDeviceId 123 -TargetGroupId 456,457 -PropertyNames "location","department"
# Copy properties from random device in source group
Copy-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 $props

This command copies properties from a source device to one or more device groups. See the documentation for all options.

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:

Terminal window
# Copy specific properties from a device to devices
Copy-LMDevicePropertyToDevice -SourceDeviceId 123 -TargetDeviceId 456 -PropertyNames "location","department"
# Copy properties from random device in source group
Copy-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 $props

This command copies properties from a source device to one or more target devices. See the documentation for all options.

Dashboard Management

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:

Terminal window
# Find widgets using specific datasources
Find-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 path
Find-LMDashboardWidgets -DatasourceNames "Windows_Performance" -GroupPathSearchString "*/Production/*"
# Pipe datasource names
"SNMP_Network_Interfaces","Windows_Performance" | Find-LMDashboardWidgets

This command helps locate dashboard widgets that use specific datasources. See the documentation for advanced search options.