VMware Cloud Community
AndreiSimba
Contributor
Contributor

Invoke-VMScript fails with "Could not locate "Bat" script interpreter in any of the expected locations"

Hello,

In our automation we came to a point where it looks useful to call scripts with in guest OS. I intend to call perl but since it's not supported I tried Bat and Powershell types. Both fail with the same message - could not locate interpreter. I should have enough privileges, including all guest ones. and of course I tried all these commands in guest without any problem. Any ideas what might be missing?

Host is running esxi 6.0, guest W2K12. Tools are up-to-date

Thank you  in advance,

++Andrei

PS H:\> Invoke-VMScript -VM $vm -scripttext "echo Hello" -ScriptType bat -GuestUser u1 -GuestPassword pw

Invoke-VMScript : 03-Dec-2015 5:28:13 PM    Invoke-VMScript        Error occured while executing script on guest OS in

VM 'B2-W2K12R2-tv002-002'. Could not locate "Bat" script interpreter in any of the expected locations. Probably you do

not have enough permissions to execute command within guest.

At line:1 char:1

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

Did you try these commands in the guest while logged on as user u1 ?

There have been reports in the past with similar error messages.

There it was due to the fact that the guest OS was started just before the Invoke-VMScript, and the guest OS and/or the VMware Tools were not completely started yet.

Could you try by adding a wait time after the Start-VM ?


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

Reply
0 Kudos
AndreiSimba
Contributor
Contributor

Of course, all commands I first tested on the target guest as same user. Note that I keep it running, it's not a newly started VM. And at the moment I am simply trying to establish proof of concept, so I am simply sending "echo" command. If I enter wrong passwd the error is different indicating wrong credentials. So I assume it gets to the point where it tries to execute within VM... Is there any log I could check for more details? I have full access to host and guest.

++A

Reply
0 Kudos
sajal1
VMware Employee
VMware Employee

Hello,

Check the format. Here you are simply running "echo" command. So you are just running the command. Just remove the "ScriptType bat" portion and it should run fine.

If you want to run a remote PowerShell format then the format of the passed command should be:

$script = '&"$env:ProgramFiles\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report "$env:Tmp\inforeport"'  Invoke-VMScript -ScriptText $script -VM VM -GuestCredential $guestCredential

Runs a PowerShell script. In PowerShell, to access environment variables, you must use the following syntax: $env:<environment variable> (for example, $env:ProgramFiles). Also, to run the program, you must specify an ampersand (&) in front of the program path.
The outer quotes ($script = '...') are required because this is how you define a string variable in PowerShell. The inner double quotes are required because there are spaces in the path.

Similarly if you want to run a remote Batch script then the format is as given below:

$script = '"%programfiles%\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report "%tmp%\inforeport"'  Invoke-VMScript -ScriptText $script -VM VM -GuestCredential $guestCredential -ScriptType Bat

Runs a BAT script. In BAT scripts, to access environment variables, you must use the following syntax: %<environment variable>% (for example, %programfiles%).

The outer quotes ($script = '...') are required because this is how you define a string variable in PowerShell. The inner double quotes are required because there are spaces in the path.

So when you specify the scripttype as "Bat" then you need to follow the syntax as well.

At the end, in your example just do not specify any "ScriptType" parameter and it should run fine.

Reply
0 Kudos
AndreiSimba
Contributor
Contributor

Removing -Scripttype results in only changing what script cannot be found - Powershell:

"Could not locate "Powershell" script interpreter in any of the expected locations."

Exact same message if I try other formats you suggested... Could this be something about rights?

Reply
0 Kudos
sajal1
VMware Employee
VMware Employee

Need to dig deeper. By the way LucD did a gr8 blog post on it http://www.lucd.info/2012/01/01/will-invoke-vmscript-work/ . Also there was another blog with some troubleshooting Invoke-VMScript Failed - and how I was Baffled. | Technodrone . Though your case is different.

Probably I can check in my lab. in the meant time, Since it is Windows 2k12 machine you an try Invoke-Command cmdlet as well. Details about this can be found here (Invoke-Command).

On windows platform "Invoke-Command" works like a charm.

Reply
0 Kudos
AndreiSimba
Contributor
Contributor

Thanks sajal1, it  lead to another idea. As Invoke-Command still failed for me I am now thinking this because the VM I am trying to access is not joined to any domain, it's in a workgroup. This article suggests it could be the problem:

https://technet.microsoft.com/en-us/magazine/ff700227.aspx

Though, I was hoping when I run Invoke-VMScript it'll run *within* guest by vmware tools. Now I am scrambling to figure how to configure my guest to enable remote authentication...

++A

Reply
0 Kudos
sajal1
VMware Employee
VMware Employee

Hi,

Yes that may be true. The dependencies are mentioned in the Invoke-Command details page (Invoke-Command).

If the remote computer is not in a domain that the local computer trusts, the computer might not be able to authenticate the user's credentials. To add the remote computer to the list of "trusted hosts" in WS-Management, use the following command in the WSMAN provider, where <Remote-Computer-Name> is the name of the remote computer:

Set-Item -Path WSMan:\Localhost\Client\TrustedHosts -Value <Remote-Computer-Name>

Also note for remote execution WinRM must be enabled on the system.

Reply
0 Kudos