VMware Cloud Community
sturag
Contributor
Contributor

Problems with Invoke-VMScript

Hi there!

We got some problems with invoke-vmscript, the thing is that it work on some servers, but not all.

Example, 2 servers, same OS (2012R2) both on same VLAN, have the same VMWare Tools version.

Small example:

Invoke-VMScript -ScriptText 'whoami' -GuestCredential $creds -VM $VM -ScriptType Powershell 

On one server i get output, on the other nothing, just:

ScriptOutput

------------------------------------

------------------------------------

Do you have any clue were to start troubleshooting? Thanks

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Have a look in the vmware.log that belongs to the problematic VMs.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
sturag
Contributor
Contributor

Cant see anything strange in the logfile.

However.. a clue.

If i first login to the server with RDP (same creds) and then execute the invoke-vmscript i get output and it works.

If i then logout from RDP session, no output from Invoke-VMScript when trying again

Reply
0 Kudos
LucD
Leadership
Leadership

That looks as if it might be a Windows profile issue.

When there is no profile for the user, it will not be created when logging on implicitly through Invoke-VMScript.
Can you run a simple command in DOS?

Invoke-VMScript -VM $vm -ScriptType Bat -ScriptText 'dir' -GuestCredential $cred


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
sturag
Contributor
Contributor

Thats true, when were using BAT as scripttype it´s working.

Reply
0 Kudos
LucD
Leadership
Leadership

That looks as if the PowerShell script hangs because it is looking for your PowerShell profile file.
The solution is to use the NoProfile parameter on the powershell.exe command (launch as BAT).

Try if this works.

$vm = Get-VM YourVM


$cmd = @'

powershell -NonInteractive -NoProfile -Command "Get-Process"

'@

Invoke-VMScript -VM $vm -ScriptText $cmd -ScriptType Bat


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos