JacobA
Contributor
Contributor

using a powershell script to....

I am new to using PowerCLI and have a task I need to accomplish.

I am able to sign into my vCenter and run a few commands to get info, but thats about the extent so far.

What I need to do is figure out how I can manipulate VM Tools in VMs in certain clusters to start a small batch file I have. My batch file will run an .exe and remove a few directories, nothing complicated.

I've managed to connect certain commands together to list all my VMs on a certain cluster and then format the output, but I havent found a single command which interacts with VM Tools, none-the-less tells it to run a batch file.

Can anyone help out with this?

Tags (3)
0 Kudos
5 Replies
LucD
Leadership
Leadership

If you want to run a BAT file on your guests you should have a look at the Invoke-VMScript cmdlet.

Use the -ScriptType Bat parameter.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
JacobA
Contributor
Contributor

I appreciate the super-fast reply, but Im not sure this is going to work. It says in the command description that the destination needs to have PowerTools installed on it and im pretty sure a lot of my VMs dont have it.

I am going to give it a try here in a few minuntes and let you know. Smiley Happy

0 Kudos
LucD
Leadership
Leadership

Afaik, only VMware Tools are required to run BAT files.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
JacobA
Contributor
Contributor

Ok here's what I am trying--

$script = '
hcssnap1\public\eg\remove_eg.bat'

$vms = 'get-vm -location som500-low1'

Invoke-VMScript -ScriptText $script -VM $vms -GuestUser myuser -GuestPassword mypass -ScriptType Bat

Then it complains that I need to run this script in a 32-bit window. I swtich to use my 32-bit CLI, connect to my vCenter, run it again and gives me some other error which I cant understand. I did have it pop up a dialogue box wanting credentials for my host. I was happy to at least see that, so I typed them in, and then another strange error.

0 Kudos
LucD
Leadership
Leadership

The current implementation of the Invoke-VMScript cmdlet requires 2 sets of user/password pairs.

One, passed via the GuestUser/GuestPassword parameters, that has rights in the OS running on your guest.

And another pair, the HostUser/HostPassword parameters, that is used to authenticate with the ESX(i) server where your guest is running.

So your code is missing the HostUser/HostPassword pair.

According to statements from VMware this will be improved in a future build.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos