Quantcast
Viewing all articles
Browse latest Browse all 232869

Re: How to list virtual machines with related vmdk files

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-ViewTypeVirtualMachine-Property Name,LayoutEx.File | ?{$_.LayoutEx.File | ?{$_.Name -eq$strVmdkDatastorePath}} | selectname

 

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 "]" and the first character of the folder name.

 

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


Viewing all articles
Browse latest Browse all 232869

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>