VMware Cloud Community
biokovo
Enthusiast
Enthusiast
Jump to solution

How to list virtual machines with related vmdk files

Hi.

I have a vmfs folder and vmdk file with names which are not like any virtual machine name (probably becouse renaming VM name).

How can I find what VM is it?

Thanks

0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, biokovo-

You could use the standard Get-VM and Get-HardDisk cmdlets to find names of VMDKs associated with VMs.  Or, another, far faster way, would be to use everyone's favorite:  Get-View.

Since you know the datastore path for the VMDK, you can check the LayoutEx property of VMs to find the VM that has the File property with the Name value that matches said datastore path, like:

$strVmdkDatastorePath = "[mydatastore] somefolder/somefile.vmdk"
Get-View -ViewType VirtualMachine -Property Name,LayoutEx.File | ?{$_.LayoutEx.File | ?{$_.Name -eq $strVmdkDatastorePath}} | select name

Where the datastore path is of format, "[datastoreName] folder/somefile.vmdk".  Yes, including the square brackets around the datastore name, and a space after the "]" (before the first character of the folder name).

How does that do for you?  (should be right quick)

View solution in original post

0 Kudos
3 Replies
mattboren
Expert
Expert
Jump to solution

Hello, biokovo-

You could use the standard Get-VM and Get-HardDisk cmdlets to find names of VMDKs associated with VMs.  Or, another, far faster way, would be to use everyone's favorite:  Get-View.

Since you know the datastore path for the VMDK, you can check the LayoutEx property of VMs to find the VM that has the File property with the Name value that matches said datastore path, like:

$strVmdkDatastorePath = "[mydatastore] somefolder/somefile.vmdk"
Get-View -ViewType VirtualMachine -Property Name,LayoutEx.File | ?{$_.LayoutEx.File | ?{$_.Name -eq $strVmdkDatastorePath}} | select name

Where the datastore path is of format, "[datastoreName] folder/somefile.vmdk".  Yes, including the square brackets around the datastore name, and a space after the "]" (before the first character of the folder name).

How does that do for you?  (should be right quick)

0 Kudos
Lessi001
Enthusiast
Enthusiast
Jump to solution

Hi,

I had the same problem, I use the script you can find here:

http://www.running-system.com/code-snippet-report-with-vm-name-lun-name-vmdk-file-and-path/

Regards

Andi

There are 10 types of people in this world. Those who understand binary, and those who do not.
biokovo
Enthusiast
Enthusiast
Jump to solution

Thanks on good advice and link, it was helpfull.

I find one more (fast) way: RV Tools.

Regards

0 Kudos