VMware Cloud Community
Muhammedali
Contributor
Contributor

Invoke-VMScript error on Win2003 machin

Hi,

I was using the Invoke-VMScript Command to run a bat file on my VM from my local machine.

when i run it on a Win7 machine, loaded with vsphereclient UI software v4.1, PowerCLI installs v4.1 and VIX v1.10.2 the commands runs well

$batfile = '"C:\Files\batchfiles\BatchFile1.bat"'

Invoke-VMScript -VM $VMName -ScriptText $batfile -GuestUser Administrator -GuestPassword password -ScriptType bat

the output is perfect as expected.

however when i run this cmdlet on a Win2003 machine, on which i installed only PowerCLI installs v4.1 and VIX v1.10.2. I get the error as shown in the image attached.

Any suggestions how to solve this?

Tags (1)
Reply
0 Kudos
25 Replies
alefestaedist
Hot Shot
Hot Shot

Is the script trying to invoke  a VM named "win_xp_----" in a storage called [SAN1] is the right VM I mean the win2003 VM or you are trying to invoke the script remotely on a different vm?

alex

Reply
0 Kudos
Muhammedali
Contributor
Contributor

The name of the file which is given in the Error message is definitely not the file i want to invoke.

Infact i'm trying to invoke a bat file which is on the VM

My local machine is Wind 2003 machine from which i'm running the PCLI cmdlets via PowerCLI

THe VM is Wind XP machine, on which i want to run bat files

Reply
0 Kudos
LucD
Leadership
Leadership

I assume you're connected to a vCenter ?

If yes, try adding the ESX credentials (parameters HostUser and HostPassword).

Peraps a stupid question, but are the VMware Tools installed on the W2K3 guest ?


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

Reply
0 Kudos
Muhammedali
Contributor
Contributor

I'm connected to a vSphereClient but from a 3rd computer.

On the Win2k3 machine, I have only installed, PowercCLI v4.1 and VIX v1.10.2 (NO VsphereClient v4.1 is installed)

on the VM i have installed VIXv1.10.2

Reply
0 Kudos
alefestaedist
Hot Shot
Hot Shot

When you invoke a script to run/manage a VM remotely you have to access to the ESX/vCenter that contain the VM itself so you have to login through powercli first.

this thread may help you understand why and how

http://communities.vmware.com/thread/232258

Reply
0 Kudos
LucD
Leadership
Leadership

To use Invoke-VMScript you need the following

  • On the calling station (where you run Invoke-VMScript)
    • PowerCLI, which will install Vix
  • on the target guest
    • up-to-date VMware tools
    • PowerShell when you want to run something with -ScriptType PowerShell
  • Network connectivity (port 902) between the calling station and the target guest

When you are connected to an ESX(i) server, you don't have to speficy the -HostUser & -HostPassword

When you are connected to a vCenter, you need to pass -HostUser & -HostPassword


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

Reply
0 Kudos
Muhammedali
Contributor
Contributor

Hi LucD,

After giving the command as

$batfile = '"C:\Files\batchfiles\BatchFile1.bat"'

Invoke-VMScript -VM $VMName -ScriptText $batfile -HostUser <user name of my Vcenter Server> -HostPassword <Vcenter server password> -GuestUser <administrator user login of my VM> -GuestPassword <Password of my VM for the respective login> -ScriptType bat

Are these parameter for HostUser, HostPassword , GuestUser, GuestPassword correct???

I get the error as shown in image attached below

Reply
0 Kudos
alefestaedist
Hot Shot
Hot Shot

Hi there, I would say that the error you got is that you cannot resolve the DNS name of your host, try with the IP directly.

Alex

P.s.: be cafrefull in the gif attached your password is in clear...one never know

Reply
0 Kudos
LucD
Leadership
Leadership

No, I'm afraid you have to give credentials for the ESX(i) host where the VM is running.

The file "C:\Files\batchfiles\BatchFile1.bat" must be present in the guest.

The error message seems to indicate that the VMware Tools are not installed or are not running.

This is a simple example

Invoke-VMScript -VM (Get-VM MyVM) -ScriptType bat -ScriptText "dir" -GuestUser <guestaccount> -GuestPassword <guestpswd> -HostUser <ESX-account> -HostPassword <ESXpswd>


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

Reply
0 Kudos
Muhammedali
Contributor
Contributor

Thanks Alex, I hav updated the image.

I'm a bit confused here. The IP you are refering to is the ip of my VM right? Where do i give this IP in the Invoke-VMScript command??

Reply
0 Kudos
LucD
Leadership
Leadership

That message has nothing to do with name resolution afaik.

This is the message you typically get when you don't give the -HostUser & -HostPassword parameter while connected to a vCenter.


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

Reply
0 Kudos
Muhammedali
Contributor
Contributor

Hi LucD

This is what i gave

Invoke-VMScript -VM (Get-VM MyVM) -ScriptType bat -ScriptText $batfilepath -GuestUser <i gave the Admnistrator account of the VM on which i want to run the bat file> -GuestPassword <password of respective -GuestUser value> -HostUser <user login for my ESX on which my VM is running> -HostPassword <password for my ESX on which my VM is running>

I'm still having the same error as before

are these parameters correct??

When you mention that the VMware Tools are not running, is there any specific tool that you are refering to ? eg. vsphere client? VIX?

Reply
0 Kudos
LucD
Leadership
Leadership

Do a

Get-VM MyVM | Select -ExpandProperty Guest

Do you see under State the value "running" ?

If not you will have to install the VMware Tools on the guest.

Easiest is to do this from the vSphere client, right-click the guest and select <Guest><Install/Upgrade VMware Tools>.

This will add a number of device drivers to the OS in the guest but it will also allow VIX calls to the guest.

And Invoke-VMScript is using VIX API to execute the script inside the guest.

Btw does this BAT-file that you pass exist inside the guest ?


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

Reply
0 Kudos
Pavel_Dimitrov
VMware Employee
VMware Employee

Hi Muhammedali,

Note that before the error message, you've got a warning about the VIX version that you're using - it does not match the recommended one. I think that this is the most probable reason for your problem. Look what's using the VIX, that's installed on your machine and if possible try to remove both PowerCLI and VIX and then reinstall PowerCLI - this way the proper VIX version will be installed.

Note that if you have any specific dependencies on the VIX version that you have, this manipulation may cause some other VMWare product to have problem (so be cautious and snapshot your VM before trying this)

Regards,

Pavel

Reply
0 Kudos
LucD
Leadership
Leadership

Hi Pavel,

That would mean that the same message is used for several issues.

I have the correct VIX version, but when I leave out the host credentials, while connected to a vCenter, I seem to get the same message.

invoke-resolve.png


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

Reply
0 Kudos
Pavel_Dimitrov
VMware Employee
VMware Employee

Yes Luc, if my assumption is right, then it really is a misguiding error message and I'll log a bug.

Reply
0 Kudos
Muhammedali
Contributor
Contributor

Hi LucD

PS E:\VMWare\BHM\PCI_Scripts> Get-VM MYVM | Select -ExpandProperty Guest

it gives me

State          IPAddress            OSFullName
-----          ---------            ----------
Running        {IP value of my VM}      Microsoft Windows XP Professional (32-bit)

Just to bring to your notice on the VM i dont have PowerCLI v4.1 installed, is that a must??

On the VM i do have the bat file present that i want to run remotely

Reply
0 Kudos
Pavel_Dimitrov
VMware Employee
VMware Employee

Another guess (maybe alefestaedist have meant the same) is that you do not have direct visibility to the host where win2003 machine is running. Try to connect directly to the host, from the machine where you're calling Invoke-VMScript.

Reply
0 Kudos
alefestaedist
Hot Shot
Hot Shot

Hi Pavlov,

yes that was what I meant , a simple connection issue..I saw that in the script the VM was pointed with the fqdn so not sure that the w23k machine could connect correctly.

Alex

Reply
0 Kudos