Forum Discussion
7 years ago
I was able to get this figured out and used the following to update the LM display names with the AWS system tag and only when the AWS tag is present. I could use a way to better handle errors when LM finds a duplicate or when there are invalid characters in the tag, but it does the job:
#Get AWS devices with name tag set (not null)
$aws=Get-LogicMonitorDevices -AccessId $lmid -AccessKey $lmkey -AccountName $lmacct | select id,displayName,systemProperties | where {$_.systemProperties -like "*system.aws.tag.name*"}
#Build list of devices including ID, LM Display Name, and AWS Tag Name
$list = @()
foreach ($device in $aws) {
$item = New-Object psobject
$item | Add-Member -type NoteProperty -Name 'id' -Value $device.id
$item | Add-Member -type NoteProperty -Name 'displayName' -Value $device.displayName
$item | Add-Member -type NoteProperty -Name 'awsTag' -Value (Get-LogicMonitorDeviceProperties -AccessId $lmid -AccessKey $lmkey -AccountName $lmacct -DeviceId $device.id | select name,value | where {($_.name -eq "system.aws.tag.Name")} | select value)
$list += $item
}
#Create list of objects to update where the display name does not currently equal the AWS tag name.
$update=$list | where {$_.displayName -ne $_.awsTag.value}
#Process Update
foreach ($item in $update) {Update-LogicMonitorDeviceProperties -AccessId $lmid -AccessKey $lmkey -AccountName $lmacct -DeviceId $item.id -PropertyNames displayName -PropertyValues $item.awsTag.value}
Related Content
- 4 months ago
- 11 months ago
- 8 months ago
- 2 years ago