You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Example CSV:# id,displayname,description,properties,collector_id,group_ids# "192.168.1.1","core-switch01","TX HQ switch","snmp.community=public,location=Austin TX","1","2,4,6"# "192.168.2.1","core-switch02","FL HQ switch","snmp.community=public,location=Orlando FL","2","7,8,9"#$csvPath="path/to/import.csv"$devices=Import-Csv-Path $csvPathforeach($devicein$devices){
#Break properties into hashtable$properties=@{}
$device.properties.Split(",") |ConvertFrom-StringData|ForEach-Object {$properties+=$_}
#Create array of group ids if adding to more than one static group$hostGroups=@($device.group_ids-split",")
#Create new device in LMNew-LMDevice-Name $device.ip-DisplayName $device.displayname-Description $device.description-properties $properties-PreferredCollectorId $device.collector_id-HostGroupIds $hostGroups
}
Import new device groups from CSV including properties
#Note:this assumes parent folder names being specified are unique in the portal since we are only using ParentGroupName to specify target group and not ParentGroupId## Example CSV:# parent_folder,name,description,properties# "portalname","Locations","All Resources",""# "Locations","NA","North America Resources","snmp.community=na-snmp"# "Locations","EURO","Europe Resources","snmp.community=euro-snmp"# "Locations","APAC","Asia Pacific Resources","snmp.community=apac-snmp"#$csvPath="path/to/import.csv"$groups=Import-Csv-Path $csvPathforeach($groupin$groups){
#Break properties into hashtable$properties=@{}
$groups.properties.Split(",") |ConvertFrom-StringData|ForEach-Object {$properties+=$_}
#Create new device group in LMNew-LMDeviceGroup-Name $group.name-ParentGroupName $group.parent_folder-Description $group.description-properties $properties
}
Export list of VM instances discovered for a vcenter resource and output inventory report
Set instance properties for a network device to override port speed
#Get device details by hostname value$Device=Get-LMDevice-Name "192.168.1.4"#Pull datasource and instance details$DataSource=Get-LMDeviceDatasourceList-id $Device.id|Where-Object {$_.dataSourceName-eq"SNMP_Network_Interfaces"}
$Instances=Get-LMDeviceDatasourceInstance-DatasourceId $Datasource.datasourceId-DeviceId $Device.id#Find instance needing to be updated$eth0=$Instances|Where-Object {$_.name-like"*eth0*"}
#Update instance with required propsSet-LMDeviceDatasourceInstance-DeviceId $Device.id-DatasourceId $DataSource.datasourceid-InstanceId $eth0.id-Properties @{"out_speed"=25;"in_speed"=500}
Remove a group of devices from a device group but do not delete them from LM
#Id of group you want to purge devices from$groupId= (Get-LMDeviceGroup-Name "Group Name").id
If($groupId){
#Get list of devices inside group we are clearing out$devices=Get-LMDeviceGroupDevices-Id $groupId#Loop through device list and remove device from $groupIdforeach($devicein$devices){
#Take existing HostGroupId list and filter out the group we wish to remove the device from$newHostGroupIdList= ($device.hostGroupIds-split (",") |? {$_-ne"$groupId"}) -join","#Update our device with the new HostGroupId listSet-LMDevice-Id $device.id-HostGroupIds $newHostGroupIdList
}
}
Bulk trigger Active Discovery for a group of devices
#Method One#Using Get-LMDeviceGroupDevices to trigger AD on a folder called Eastbridge$deviceGroupId= (Get-LMDeviceGroup-Name "Eastbridge").id
Get-LMDeviceGroupDevices-Id $deviceGroupId|Foreach-Object {Invoke-LMActiveDiscovery-Id $_.id}
#Method Two#Using Get-LMDevice to get a filtered list of devices to trigger AD againstGet-LMDevice-Name "lm*"|Foreach-Object {Invoke-LMActiveDiscovery-Id $_.id}
#Method Three#Using the parameter in the Invoke-LMActiveDiscovery to trigger AD on a folder called EastbridgeInvoke-LMActiveDiscovery-GroupName "Eastbridge"
Rename devices based on value of a given property
#Method One#Using Get-LMDeviceProperty to retrieve the value for sysname and Set-LMDevice to set the new displayName for it$deviceProperty= (Get-LMDeviceProperty-Name "192.168.1.1"-Filter "name -eq 'system.sysname'").value
Set-LMDevice-Name "192.168.1.1"-DisplayName $deviceProperty#Method Two#Using Get-LMDevice to retrieve the value for sysname and Set-LMDevice to set the new displayName$device=Get-LMDevice-Name "192.168.1.1"$deviceProperty= ($device.systemProperties[$device.systemProperties.name.IndexOf("system.sysname")].value)
Set-LMDevice-Name "192.168.1.1"-DisplayName $deviceProperty#Method Three#Using Get-LMDeviceGroupDevices to retrieve a list of devices and loop through each and set the sysname value to the displayname$devices=Get-LMDeviceGroupDevices-Name "Cambium Wireless"Foreach ($devin$devices) {
$deviceProperty= ($dev.systemProperties[$dev.systemProperties.name.IndexOf("system.sysname")].value)
if($deviceProperty-and$dev.systemProperties.name.IndexOf("system.sysname") -ne-1){
Set-LMDevice-Id $dev.id-DisplayName $deviceProperty
}
}
Update/Add device property if out of date or missing
#Array to store returned objects$processedDeviceList=@()
#Get list of devices in a device group for device group id 23$devices=Get-LMDeviceGroupDevices-Id "23"#Loop through each device and check for presence of propertyForeach ($devin$devices) {
$propName="test.prop"$propValue="1234"$currentPropValue= ($dev.customProperties[$dev.customProperties.name.IndexOf($propName)].value)
if($currentPropValue-and$dev.customProperties.name.IndexOf($propName) -ne-1){
If($currentPropValue-ne$propValue){
#Update the property value since it does not match desired value$processedDeviceList+=Set-LMDevice-Id $dev.id-Properties @{$propName=$propValue}
Write-Host"Successfully processed $($dev.displayName), updated property $propName value from $currentPropValue -> $propValue"
}
Else{
#Skip device since it already has desired value:Write-Host"Skipped processing $($dev.displayName) since property $propName is already present with the desired value $propValue"
}
}
else{
#Add property and value since it does not exist on device currently$processedDeviceList+=Set-LMDevice-Id $dev.id-Properties @{$propName=$propValue}
Write-Host"Successfully processed $($dev.displayName), added property $propName with value $propValue"
}
}
#Print out results$processedDeviceList|Select-Object id,displayname,customproperties |Format-List
Export LM Device Metric Data to JSON/CSV
#Method One: Export all datasources and instances by deviceIdExport-LMDeviceData-DeviceId 3-ExportPath "../../../Desktop"-ExportFormat json
#Method Two: Export only datasources starting with Collector to CSVExport-LMDeviceData-DeviceId 3-ExportPath "../../../Desktop"-ExportFormat csv -DatasourceIncludeFilter "Collector*"#Method Three: Get HTTPS-443 instance metric data for the past 8 hoursGet-LMDeviceData-DeviceId 3-DatasourceId 72-InstanceName "443"-StartDate (Get-Date).AddHours(-8) -EndDate (Get-Date)
Import list of PingMulti instances
#Example adding ping multi via csv with headers DisplayName,Wildvalue,Description$pingList=Import-CSV ../../../Desktop/test.csv
$device=Get-LMDevice-DisplayName "lmstevenvillardi-wincol02"$pingMultiId= (Get-LMDeviceDatasourceList-Id $device.Id|Where-Object {$_.dataSourceName-eq"PingMulti-"}).dataSourceId
Foreach($linein$pingList){
New-LMDeviceDatasourceInstance-DisplayName $line.DisplayName-WildValue $line.Wildvalue-Description $line.Description-DatasourceId $pingMultiId-Id $device.id
}
Remove a category from system.categories
$CategoryToRemove="test"$Devices=Get-LMDeviceForeach($Devicein$Devices){
$Categories=$Device.customproperties.value[$Device.customProperties.name.IndexOf("system.categories")]
If($Categories-and ($Categories-Split (",")).toLower().Contains($CategoryToRemove.toLower())){
Try{
$UpdatedCategories= ($Categories-Split (",") |Where-Object {$_-ne$CategoryToRemove}) -Join","Set-LMDevice-Id $Device.Id-Properties @{"system.categories"=$UpdatedCategories}
Write-Host"Successfully updated device system.properties to remove category ($CategoryToRemove)"-ForegroundColor Green
}
Catch{
Write-Host"Unable to update device: $_"-ForegroundColor Red
}
}
Else{
Write-Host"Skipping device update, no matching systemcategories value found matching: $CategoryToRemove"
}
}
Note: PushMetrics must be enabled for the LM Portal
#Example hashtable format for datapoints$Datapoints=@{
ErrorCount=0NewUsersCreated=0NewUsersCreatedAsDisabled=0UsersRemovedFromGroups=0UsersWithGroupMembershipChanges=0DomainUsersUpdatedSinceLastSynchronization=0DisabledUsers=0StartDateError=0NextSynchronizationDateTimeError=0
}
#Create PushMetric datapoint object using hashtable$DatapointsObject=New-LMPushMetricDataPoint-DataPoints $Datapoints#Create instance object using datapoint object from previous command$InstanceObj=New-LMPushMetricInstance-Datapoints $DatapointsObject-InstanceName "Test"-InstanceDisplayName "Test Description"#Send PushMetric to LM using the instance object created in the previous command along with the specified datasource and resource mapping parametersSend-LMPushMetric-Instances $InstanceObj-DatasourceName "My_First_Push_Metric"-DatasourceDisplayName "My First Push Metric"-ResourceIds @{"system.displayname"="LM-COLL"}