Convert VMWare PowerCLI Invoke-VMScript Output into PSObjects Array

There is a very usefull CMDLet Invoke-VMScript which comes with VMWare PowerCLI. You can use it to run the PowerShell scripts against a virtual machine (VM).
The CMDLet has several advantages over native PowerShell 2.0 remoting:
1. Avoiding one hop while executing the script (on the VM, the script is executed from the first person).
2. Ability to run the script against host-only VMs.

The only trouble is that this CMDLet returns the results as raw text which is not possible to handle like a PSObjects array.

To workaround this issue, you can use the following approach:

Invoke-VMScript -VM VirtualMachineName -ScriptText “Your script here | ConvertTo-CSV -NoTypeInformation” -HostUser root -HostPassword “rootpassword” -GuestUser DOMAIN\admin -GuestPassword “adminpassword” | ConvertFrom-CSV

Advertisements