Nothing fancy here. I just need a basic query that will find (fixed disk) volumes across all nodes that have the word "merged" in their path name, and delete them.
SWQL is a read-only interface, so it can get you the list, but then you'll need to call a verb to delete the things. In PowerShell, you'd use the Remove-SwisObject function, but other languages are also supported.
Remove-SwisObject
Depending on what exactly you mean for your filter, this will probably work.
SELECT [Volumes].DisplayName AS [Volume] , [Volumes].Node.DisplayName AS [Node] , [Volumes].Uri AS [VolumeUri]FROM Orion.Volumes AS [Volumes]WHERE [Volumes].Type = 'Fixed Disk' AND ( [Volumes].DisplayName LIKE '%merged%' OR [Volumes].DeviceId LIKE '%merged%' )
Thank you! The output is exactly what I was looking for. Now I'm having an issue with my Powershell to remove. See the error below and my PS script. The $uris output is correct. A quick search shows this may be related to not using swis v3? Could you advise on how to properly state my endpoint if this is the case?
Import-Module -Name SwisPowerShell$SwisParams = @{ Hostname = ''; Username = ''; Password = '';}$swis = Connect-Swis @SwisParams$uris = Get-SwisData $swis "SELECT [Volumes].DisplayName AS [Volume] , [Volumes].Node.DisplayName AS [Node] , [Volumes].Uri AS [VolumeUri]FROM Orion.Volumes AS [Volumes]WHERE [Volumes].Type = 'Fixed Disk' AND ( [Volumes].DisplayName LIKE '%merged%' OR [Volumes].DeviceId LIKE '%merged%' )"#$uris | Remove-SwisObject $swis#$uris | Out-GridView -Title "Merged Volumes"
I'm not sure that Remove-SwisObject is built to allow pipeline. I've honestly never tried it. I'd do it as a ForEach or ForEach-Object to rule that out. Are you getting anything if you remove the comment from the final line?
ForEach
ForEach-Object
Yes, the Out-Gridview works fine and displays all of the volumes I'd expect to see from the query. I have another script where Remove-SwisObject works fine with pipeline so I'm a bit stumped on why this particular script doesn't work.
Is there another powershell function I could use to delete volumes in bulk?
I can't recall specifics on where I saw this recommendation but try sanitizing your Uri's first, I do this in some of my powershell scripts. Once you've got your data imported in some way and in an object...
$UrisToRemove = @( $objectWithVolumeData.Uri | ForEach-Object { [string] $_ } )$UrisToRemove | Remove-SwisObject -SwisConnection $swis
@LatteLarry... I didn't even notice your powershell sorry. When piping to remove-swisobject it should only be a list of Uri's.
So a simple way to do that in your existing script is changing $uris | remove... to $uris.Uri | remove....
Thanks for the responses. Just before your first response, I was able to determine the problem was related to the swql query. I think it was something related to the AND or OR statement. I simplified the query a bit and was able to use the powershell script as is. All is good now. If I have a moment I may try to pinpoint exactly what it was in the query for my own sanity and learning.I appreciate all the help!