Reputation: 89
I have one problem with two questions. I have following powercli cmd:
$snapLst = Get-VM vmindev |Get-Snapshot |Select VM, Name, Description, `
@{Name='Created'; Expression={{$_.Created.ToString("yyMMdd")}}, `
@{Name='SizeMB'; Expression={[int] $_.SizeMB}}
$resultLst=$snapLst| where SizeMB -gt 1000 |Sort-Object SizeMB |`
Select @{Name='Type'; Expression={'BIG'}},*
When run in my DEV env (powercli session on my desktop connecting to the vSphere sever), everything is fine. When run in PRODUCTION (ie. powercli session on the vSphere server), I get the following error:
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "SizeMB" value of type "System.String" to type System.Management.Automation.ScriptBlock".
At C:\Users\kness\Scripts\sn2.ps1:32 char:27
+ $resultLst=$snapLst| where <<<< SizeMB -gt 1000 |Sort-Object SizeMB |Select
@{Name='Type'; Expression={'BIG'}},
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand
Q1: What - in the environment setup - would make the script behaves differently? I checked the versions of the powercli ... they're exactly the same.
Q2: Because the above error, I look into the property of the list by running this cmd:
$snapLst = Get-VM vmindev |Get-Snapshot |Get-Member |Findstr Size
SizeGB Property System.Nullable`1[[System.Decimal, mscorlib, Ve...
SizeMB Property System.Decimal SizeMB {get;}
SizeMB is a "decimal" type; why the error complains that it is a "string"?
Thx in advance!
Upvotes: 3
Views: 5164
Reputation: 89
I got it resolved with helps fr TessellatingHeckler.
A1. Although my PowerCLI package is the same, it operates on two different Powershell installation. On my desktop, PSVersion is 4.0 and on the production server, it is 2.0
A2. This is related to A1. In PS 4.0, the cmdlet where is translated properly to Where-Object {...}. Whereas in PS 2.0, it is a syntax error. The complain about SizeMB being System.String is just a red herring following the "where" syntax error.
By changing where SizeMB -gt 1000 to Where-Object {$_.SizeMB -gt 1000} the script is now working. I guess, the alternative would be to upgrade the PS on the vSphere server ... but I dont want to go there. Thanks for your helps everyone.
Upvotes: 5