Closed MPrica12 closed 1 year ago
The Tags
property is an array. The -like
and -notlike
operators apply to strings. To analyze an array, consider using the -in
and -notin
filters
# Get all sensors that DON'T have the "monitoring-event" tag
$sensors = Get-Sensor | where { "monitoring-event" -notin $_.Tags }
If you need to filter for sensors containing a tag that matches a wildcard expression, this is a bit more complicated
# Get all sensors that DON'T have any tags like "incident-p*"
$sensors = Get-Sensor | where { !($_.Tags|where { $_ -like "incident-p*" }) }
Combining these two techniques, you can do the following
# Get all sensors that don't contain the tag "monitoring-event" or a tag like "incident-p*"
Get-Sensor | where { ("monitoring-event" -notin $_.Tags) -and !($_.Tags|where { $_ -like "incident-p*" }) }
# Get all sensors that do contain the tag "monitoring-event" or a tag like "incident-p*"
Get-Sensor | where { ("monitoring-event" -in $_.Tags) -or ($_.Tags|where { $_ -like "incident-p*" }) }
The
Tags
property is an array. The-like
and-notlike
operators apply to strings. To analyze an array, consider using the-in
and-notin
filters# Get all sensors that DON'T have the "monitoring-event" tag $sensors = Get-Sensor | where { "monitoring-event" -notin $_.Tags }
If you need to filter for sensors containing a tag that matches a wildcard expression, this is a bit more complicated
# Get all sensors that DON'T have any tags like "incident-p*" $sensors = Get-Sensor | where { !($_.Tags|where { $_ -like "incident-p*" }) }
Combining these two techniques, you can do the following
# Get all sensors that don't contain the tag "monitoring-event" or a tag like "incident-p*" Get-Sensor | where { ("monitoring-event" -notin $_.Tags) -and !($_.Tags|where { $_ -like "incident-p*" }) }
# Get all sensors that do contain the tag "monitoring-event" or a tag like "incident-p*" Get-Sensor | where { ("monitoring-event" -in $_.Tags) -or ($_.Tags|where { $_ -like "incident-p*" }) }
Thank you so much for this!! It worked as expected
Describe the bug
Hello,
So I currently am trying to use the PrtgAPI to gather all of the sensors present in our system that do not have the following tags: "monitoring-event" or "incident-p".
The issue is that whenever I try to do it using a simple where check the variable always stores ALL of the sensors in Prtg, so no filtering is applied.
I have tried 2 different instances for comparison, -like and -notlike, what is weird is the fact that using -like works but -notlike always retrieves every sensor, below is the command I am using:
Steps to reproduce
What is the output of 'Get-PrtgClient -Diagnostic'?
Additional context
No response