Don’t ask me why but I wanted a list of .VMX files for all of the virtual machines registered in vCenter. With a little experimentation it was easy to come up with a oneliner.

[ps]Get-VM | Get-View | % { $_.Config.Files.VmPathName }[/ps]

However, that’s not the quickest way. The output takes ages to display because each VM is passed along the pipeline one at a time resulting in multiple Get-View queries. The following is faster:

[ps]Get-View -ViewType VirtualMachine | % { $_.Config.Files.VmPathName }[/ps]

Although it is a bigger query, the single Get-View call makes the whole thing so much faster. I learned that the other week at a fantastic VMware event. Cheers Alan.

Now, one question I have. Most of the VMX files returned by this take the following form:

[text][datastore_name] VM-Name/VM-Name.vmx[/text]

However, there were a few that came out as:

[text][] /vmfs/volumes/datastore-id-string/VM-Name/VM-Name.vmx[/text]

Does anyone know why that’s happening? They’re all from the same datastore, perhaps there’s an issue with that…

Leave A Reply

Your email address will not be published. Required fields are marked *