Find Virtual Machine Configuration File Path using Powercli


Today’s post is titled Find Virtual Machine Configuration File Path using Powercli. I was recently working with a customer whose task was to find out how to perform a sanity check of the datastores within the vSphere environment.

The reason behind this task was that many of the Virtual Machines were removed from inventory and the customer was not sure on how to clear up the datastores.

So, he was looking for an easy way to find out the list of VMs that were currently registered to the vCenter Server and the path to the Virtual Machine configuration file so that he doesn’t delete the files that were associated with the VMs already registered.

Normally, you would go to the Virtual Machine settings and from the options tab to find the path of the Virtual Machine Configuration file.

Now doing this for one or two VMs is fine, but performing this step manually for all the VMs in the inventory can be a painful task.

Hence, I decided to a small function that will help you select a Virtual Machine and provide the Display Name and the path to its configuration file.

If you like an easy way to this, then below is the one-liner which will list all the VMs with the config file path.

Get-VM | select Name,@{E={$_.ExtensionData.Config.Files.VmPathName};L=”VM Path”}

Find Virtual Machine Configuration File Path using Powercli

You can find the function that I have written below.

So, there are a couple of ways that you can run this function. The first one is to directly call the function and provide the parameter which accepts the VM name.

Get-VMConfigFile VCSA65-A

Find Virtual Machine Configuration File Path using Powercli

The second is to pipe the output of Get-VM cmdlet to the function.

Get-VM VCSA65-B | Get-VMConfigFile

Find Virtual Machine Configuration File Path using Powercli

I hope this has been informative and thank you for reading!


About Author

I am Adil Arif, working as a Technical Support Engineer at VMware as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.

Leave A Reply

If so, please join the community.  I’d love to send you exclusive content right to your email, and I’ll send you a free copy of my book, VMware vSphere 6.0 Lab on Workstation too!
Enter your name and email below, and I’ll see you on the inside!