Active2 years, 2 months ago
I have a PowerShell 2.0 script that I use to clone a target vmware workstation guest using vmrun in a windows host environment.The code to clone a virtual machine executes correctly.
The Basics and Syntax of vmrun. The type of VMware product which is running on the host. Options are ws for VMware Workstation, server for VMware Server 2 and server1 for VMware Server 1.u The user name on the host to be used to log into the VMware management interface. The same as the user name that would be used when logging in using the VI Web Access interface.
I am now trying to expand on this script to automate more of the process, for example, to check to see if a virtual machine is running,
vmrun list
, and to stop the virtual machine, vmrun stop [pathToVMXfile]
if running. With a windows command prompt, when I run
vmrun list
, it returns the following:Total running VMs: 2
D:[path][name].vmx
E:[path][name].vmx
D:[path][name].vmx
E:[path][name].vmx
When I attempt the following in PowerShell, nothing returns. Here is what I have attempted so far. I am expecting an array to return with the values I see when I run from a command prompt.
No matter what I attempt, I do not get any output. What am I missing? Note: Vmrun command line documentation is found here: 'https://www.vmware.com/support/developer/vix-api/vix112_vmrun_command.pdf'
Thanks.
Daniel Lee
Daniel LeeDaniel Lee44911 gold badge77 silver badges1919 bronze badges
1 Answer
I found a similar post here: Capturing standard out and error with Start-Process
For whatever reason the powershell solution doesn't send results of the process to the -OutVariable as I expected.
So instead I followed the steps on the page indicated to create a new
Daniel LeeDaniel Lee$pinfo = New-Object System.Diagnostics.ProcessStartInfo
.I set the corresponding properties and then started the process using System.Diagnostics.Process and it allows me to output the results to a string variable. 44911 gold badge77 silver badges1919 bronze badges