Author Posts

August 27, 2014 at 9:52 am

Hi,

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: (:) [Get-EC2Volume], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Amazon.PowerShell.Cmdlets.EC2.GetEC2VolumeCmdlet" Any help would be appreciated. Thanks

August 27, 2014 at 9:56 am

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 http://docs.aws.amazon.com/powershell/latest/userguide/pstools-ec2-get-amis.html )

August 27, 2014 at 10:45 am

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: (:) [New-Object], Exception + FullyQualifiedErrorId : InvalidValue,Microsoft.PowerShell.Commands.NewObjectCommand I tried "detached" as well and it came back with the same error.

August 27, 2014 at 11:10 am

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 http://aws.amazon.com/sdk-for-net/#version2

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')

August 27, 2014 at 11:51 am

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

Thanks again, Dave.