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.
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
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.
$vmwareRun = "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe"
#Original test, also tried with single quotes and no quotes,
#also tried quoting the -filePath
Start-Process $vmwareRun -ArgumentList "list"
#This gives a handle to the process but no return value
$myProcess = Start-Process $vmwareRun -ArgumentList "list" -PassThru
#$t is empty
Start-Process $vmwareRun -ArgumentList "list" -OutVariable $t
#$t is empty, clone command requires the -T ws parameters
Start-Process $vmwareRun -ArgumentList "-T ws list" -OutVariable $t
#RedirectStandardOutput creates a file with the expected output, $t is empty
Start-Process -FilePath "$vmwareRun" -ArgumentList $argList -OutVariable $t -RedirectStandardError "C:\testError.log" -RedirectStandardOutput C:\testOut.log"
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.