I am creating a basic script that will ultimately automatically remove loopback, mgmt., null interfaces and others once a week. The script below does return Uri's as intended however when I add the remove object statement it throws an error I do not understand
$ErrorActionPreference = 'Stop'
#Add the snapin
Add-PSSnapin SwisSnapin
#create a connection to solarwinds
$hostname = '10.X.X.X'
$username = 'admin'
$password = 'XXXXX'
#swis = Connect-Swis -Hostanme $hostname -Trusted
$swis = Connect-Swis -Hostname $hostname -Username $username -Password $password
#Query Data
$query = Get-SwisData $swis "Select uri FROM Orion.NPM.interfaces WHERE InterfaceName = 'lo'"
# This returns the following Uri's
swis://XXXX.my.domain.net/Orion/Orion.Nodes/NodeID=123/Interfaces/InterfaceID=321
swis://XXXX.my.domain.net/Orion/Orion.Nodes/NodeID=456/Interfaces/InterfaceID=654
swis://XXXX.my.domain.net/Orion/Orion.Nodes/NodeID=789/Interfaces/InterfaceID=987
# When adding the final remove object line...
$query | ForEach-Object { Remove-SwisObject $swis $query }
I get the error below
ForEach-Object : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter
'Uri'. Specified method is not supported.
At C:\Users\nsd000.QACMA\Documents\PowerShell Scripts\Do not Modify\Delete Loopbacks MGMT and Null
Interfaces.ps1:22 char:10
+ $query | ForEach-Object { Remove-SwisObject $swis $query }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.ForEachObjectComma
nd
This format works well when I use the same logic on the script below. The only difference I can see is that the script above is pulling from Orion.NPM.Interfaces and the one below is Orion.Volumes
$ErrorActionPreference = 'Stop'
#Add the snapin
Add-PSSnapin SwisSnapin
#create a connection to solarwinds
$hostname = '10.xXX'
$username = 'admin'
$password = 'XXXXX'
#swis = Connect-Swis -Hostanme $hostname -Trusted
$swis = Connect-Swis -Hostname $hostname -Username $username -Password $password
#Query Data
$query = Get-SwisData $swis "Select uri FROM Orion.volumes WHERE VolumeDescription = 'Cached Memory' AND VolumePercentUsed ='100'"
# Remove Objects
$query | ForEach-Object { Remove-SwisObject $swis $query }