EC2 Volumes detached list


Just looking for a bit of guidance. I’m trying to have PowerShell give me a list of rogue volumes (volumes not attached to any instance) but the example Amazon is giving isn’t working:

Get-EC2Volume -Filters @{ Name=“status”; Values=“available” }

I get this:
"Get-EC2Volume : Cannot bind parameter ‘Filters’. Cannot convert the “System.Collections.Hashtable” value of type “Syste
m.Collections.Hashtable” to type “Amazon.EC2.Model.Filter”.
At line:1 char:23

  • Get-EC2Volume -Filters <<<< @{ Name="status"; Values="available" }
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-EC2Volume], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Amazon.PowerShell.Cmdlets.EC2.GetEC2VolumeCmdlet"

Any help would be appreciated.


Try this:

$filter = New-Object Amazon.EC2.Model.Filter -Property @{ Name="status"; Values="available" }

Get-EC2Volume -Filters $filter

(I haven’t used AWS to test this myself, but based it on documentation found at Find an Amazon Machine Image Using Windows PowerShell - AWS Tools for PowerShell )

Thanks, Dave.

But that is coming back with this error:

New-Object : The value supplied is not valid, or the property is read-only. Change the value, and then try again.
At line:1 char:21

  • $filter = New-Object <<<< Amazon.EC2.Model.Filter -Property @{ Name="status"; Values="available" }
    • CategoryInfo : InvalidData: (:slight_smile: [New-Object], Exception
    • FullyQualifiedErrorId : InvalidValue,Microsoft.PowerShell.Commands.NewObjectCommand

I tried "detached" as well and it came back with the same error.

OK, did a bit more digging. I suspect you’re using an older version of the AWS SDK (one of the v1.x versions.) The API changed a bit in v2, which you can download from AWS SDK for .NET

Assuming you do need to use v1 for some reason, try changing “Values” to “Value” in your hashtable. Either syntax (passing the hashtable directly to the -Filters parameter, or using New-Object first) will probably work.

Edit: Another v1 syntax which might help, if the hashtables don’t:

$filter = (New-Object Amazon.EC2.Model.Filter).WithName('status').WithValue('available')

Turns out the original script works under a different machine. Just need to figure out what’s wrong with mine.

Thanks again, Dave.