VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Getting the datastore of a VM

I'm attempting to get the datastore of a VM, but format it in such a way as to be used with vmrun. My current vmrun statement is:

vmrun -T vc -h https://<ipaddress>:443/sdk -u <username> -p <password> runProgramInGuest "[<datastorename>] <datastorefolder>/<virtualmachinename>.vmx" c:\myscript.bat

So the idea is to replace <datastorename> with the name of the LUN that a given virtual machine is running on. In this case, I am running my vmrun statement from inside a PowerCLI script. So I could use a powerCLI variables, if the vmrun statement can take them, and use whatever escape sequences are required to fit the format that vmrun needs for this argument.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That is correct.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik, you can use the "[datastore] folder/name.vmx" notation in the vmrun command.

You can that path quite easily as follows

get-vm  | select Name,@{N="VMX path";E={$_.Extensiondata.Config.Files.VmPathName}}

This requires you to run PowerCLI 4.1 !

____________

Blog: LucD notes

Twitter: lucd22


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

admin
Immortal
Immortal
Jump to solution

Hi,

Why don't use Invoke-VMScript? It allows you to start process inside the guest, it does the same you want to do with vmrun.exe! Give it a try!

Vitali

PowerCLI Team

TheVMinator
Expert
Expert
Jump to solution

Ok thanks. Does Invoke-VMscript require me to know the ESX host of the VM before I write the script so that I can specify the ESX host as a parameter, or can I just log into the vCenter Server? In DRS clusters you don't always know what ESX host a VM is running on unless you use PowerCLI to discover what host it is currently on - just logging into vCenter Server is easier if possible...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You need to provide credentials (-Hostuser & -Hostpassword or -Hostcredential) for the host your guest is running on.

So yes, you will need to know which ESX.

Unless, your ESX account are synchronised between all nodes in the cluster.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK, so assuming I have the same credentials already established on every ESX host - i.e., the same username and password, then I really don't need to know which particular host in the cluster my VM happens to be running on - I just add those credentials as arguments?

Thx

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is correct.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos