Hello Community Members,
I am seeing the below error when I try to do Format-List for a array variable. What could be the issue?
$output=@()
$vm.Name |
ForEach-Object -Process {
$output+=Invoke-VMScript -VM $_ -GuestUser '' -GuestPassword '' -ScriptText 'dir' -ScriptType Powershell -RunAsync -Confirm:$false
}
$output |fl
This looks to be a bug in PowerCLI in PSv6 and later.
Since you use the RunAsync switch, the result of the Invoke-VMScript cmdlet will be a Clien Side Task object.
This kind of object os dynamically updated when the background task completes.
Especially the Result property will now get the 'results' of the background task (like ExitCode, ScriptOutput...).
The Format-List cmdlet uses casting instead of the ToString() member method on the objects.
And that is where it goes wrong, the VMScriptResultImpl object (which is the Result property) apparently has an issue, in PSv6 and beyond, with this casting.
I would definitely open an SR to report this bug.
To bypass the issue you can leave out the RunAsync switch or use PSv5.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This looks to be a bug in PowerCLI in PSv6 and later.
Since you use the RunAsync switch, the result of the Invoke-VMScript cmdlet will be a Clien Side Task object.
This kind of object os dynamically updated when the background task completes.
Especially the Result property will now get the 'results' of the background task (like ExitCode, ScriptOutput...).
The Format-List cmdlet uses casting instead of the ToString() member method on the objects.
And that is where it goes wrong, the VMScriptResultImpl object (which is the Result property) apparently has an issue, in PSv6 and beyond, with this casting.
I would definitely open an SR to report this bug.
To bypass the issue you can leave out the RunAsync switch or use PSv5.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah You are right LucD. I have checked in psversion 5.1 and its showing up the results. Thanks letting me know the issue.