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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s