VMware Cloud Community
nrkarmarkar
Contributor
Contributor

Running Powershell process using 'Run Program in guest' workflow

Hi

I added a new vmdk disk to my windows server virtual machine and now want to bring the disk online. A simple powershell command would be

powershell.exe -command "& 'Get-Disk|?{($_.isOffline)}|Set-Disk -IsOffline $false'"

I want to execute this using 'Run Program in guest' workflow and mark the disk 'online'. The workflow executes successfully, but does not achieve intended results.

I also tried something as simple as just running notepad.exe through this workflow. I checked task manager and see the notepad process running but do not see it. I am logged in using the same credentials in the VMs as the one I am passing in the workflow.

In the inputs, I am passing fully qualified path to powershell.exe for 'programPath' whereas everything starting -command is passed as arguments.

Am I missing something?

Thanks

Nachiket

Reply
0 Kudos
3 Replies
vXav
Expert
Expert

Why don't you connect to the vCenter with PowerCLI and use VIX to invoke a script?

Connect-VIServer "MyvCenter"

$ScriptToRunInVM = 'Get-Disk|?{($_.isOffline)}|Set-Disk -IsOffline $false'

$VM = Get-VM "TheVMyouAddedADiskTo"

Invoke-VMScript -VM $VM-ScriptText $ScripToRunInVM

I haven't tried your bit though.

Better way to try these thing instead of launching notepad is to create a temp file somewhere.

Reply
0 Kudos
nrkarmarkar
Contributor
Contributor

I am not sure if I understood. Are you referring to adding vCenter server as powershell host within vRealize orchestrator?

To give a little bit of a background, bringing the disk online is part of a bigger vRO workflow. Using pre-packaged workflows and actions, it interacts with a storage array, makes a writable snapshot copy of a volume and maps it to the host. This writable snap copy is then re-signatured in the ESX host thereby making changes only to the metadata and retaining all the data identical to that of parent volume.

It is this snap copy volume where I pick the vmdk from and add it to the VM. The last stage of it is to bring the disk only backed by this vmdk. This is where I am stuck.

Thanks

Nachiket

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Try with the following parameters for 'Run program in guest' workflow:

Interactive session in guest -> yes

Program path                      -> c:\windows\system32\cmd.exe

Arguments                          -> /k C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe your-ps-command

replace your-ps-command above with your Powershell command

Reply
0 Kudos