If you specify -Verbose after each cmdlet you will probably find it hasn't hung, and will be able to see the requests that are being executed
Potentially your issue is that you haven't declared your $SensorRemovalList variable as an array.
I imagine you would have gotten an error similar to the following?
Method invocation failed because [PrtgAPI.Sensor] does not contain a method named 'op_Addition'.
At line:5 char:5
+ $sensors += $group | Get-Sensor -Tags vlan170 | where name -ne "P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Here are the results of some testing I did
PS C:\> get-sensor -tags vlan170
Name Id Device Group Probe Status
---- -- ------ ----- ----- ------
Ping 7810 NY-BRONX NY1 New York Warning
CPU Load 7811 NY-BRONX NY1 New York Unknown
When I rewrote your script how I would write it, I got the following
$groups = Get-Group
$sensors = @()
foreach($group in $groups)
{
$sensors += $group | Get-Sensor -Tags vlan170 | where name -ne "Ping"
}
$sensors | Remove-Object -WhatIf
What if: Performing the operation "Remove-Object" on target "'CPU Load' (ID: 7811)".
PS C:\> $sensors
Name Id Device Group Probe Status
---- -- ------ ----- ----- ------
CPU Load 7811 NY-BRONX NY1 New York Unknown
If you are getting an error passing something to Remove-Object, you are passing the wrong type of something. General PowerShell troubleshooting steps to take in this scenario include
1. Dump the $SensorRemovalList variable. Does it even contain anything?
2. Get the type of the $SensorRemovalList object. Was it the type you expected?
3. If $SemsorRemovalList is an array, get the type of an element of the array. In this scenario, it should be a Sensor
PS C:\> $sensors.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
PS C:\> $sensors[0].GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False Sensor PrtgAPI.Objects.Shared.SensorOrDeviceOrGroupOrProbe
Add comment