VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast

Path of VMX and Associated VSWP File Location

Hi All,

Now we are in a situation where VMX and VSWP files are in different datastores, and for some we are not able to trace VMX with associated VSWP File Location.

IS there any way to get the VMX Path based on VSWP file in datastore.

Please provide any script or any other way to find it.

Swap file location policy is set as it should store in the same directory.

0 Kudos
10 Replies
LucD
Leadership
Leadership

The following script gives an overview of the VMX location and swap file location for each VM.

foreach($vm in Get-VM){

$vm | Select Name,@{N='VMX';E={$vm.ExtensionData.Config.Files.VmPathName.Split('/')[0]}},

@{N='Swap';E={

    switch($vm.ExtensionData.Config.SwapPlacement){

'inherit' {

    $parent = Get-View $vm.ExtensionData.ResourcePool -Property Name,Parent

    while($parent -isnot [VMware.Vim.ClusterComputeResource]){

        $parent = Get-View $parent.Parent -Property Name,Parent

    }

    $parent = Get-View $parent.MoRef -Property ConfigurationEx.VmSwapPlacement

    switch($parent.ConfigurationEx.VmSwapPlacement){

    'hostLocal' {

        $esx = Get-View $vm.ExtensionData.Runtime.Host -Property Config.Local.SwapDatastore

        $swapLocation = Get-View $esx.Config.LocalSwapDatastore -Property Name

    }

    'vmDirectory' {

        $swapLocation = $vm.ExtensionData.Config.Files.VmPathName.Split('/')[0]

    }

    }

}

'hostLocal' {

        $esx = Get-View $vm.ExtensionData.Runtime.Host -Property Config.Local.SwapDatastore

        $swapLocation = Get-View $esx.Config.LocalSwapDatastore -Property Name

}

'vmDirectory' {

        $swapLocation = $vm.ExtensionData.Config.Files.VmPathName.Split('/')[0]

}

}

$swapLocation

}}}


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

Thanks for the Script, Output is having VM, VMX along with VSWP file, but here we are in a situation that VSWP file is in datastore1, and Some one have renamed this VM very long back. Not able to trace the current VM Name. IS there any script to find VMX name based on VSWP file which is in different datastore.

Please suggest.

0 Kudos
LucD
Leadership
Leadership

With the result from the script you should be able to use a Where-clause on the VSWP property.

Or do I completely misunderstand the question ?


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

We have migrated all VMs from datastore1 to datastore2.

we need to unmount datastore1 as we got datastore2 from different NFS box.

we have seen 2 different VSWP files lying inside datastore1 but we didn't see any VM with that VM Swap file name.

So we need to figure it out from where this VM is up and running based on VSWP files.

Please let me know if you would require additional details.

0 Kudos
LucD
Leadership
Leadership

Do you see datastore1 appearing anywhere in the Swap property ?

If not, then these folders/files are not used by any VM


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

HI Lucd,

I am not seeing datastore1 in any of the host.

Instead of that I am seeing Virtual Machine directory.

But I am gettting confused if VM is not running then VSWP file won't get generated.

Pls suggest

0 Kudos
LucD
Leadership
Leadership

Your screenshot seems to confirm that the swap file goes to the VM directory, not a separate datastore location.

Those folders you still see on datastore1, couldn't they be entries from VMs that are gone (or have been recreated).

What is the timestamp you see on those files on the datastore1 ?


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

Timestamp is very old 2013 year.

What could be the reason that till VSWP file is still lying on this datastore. Please help.

0 Kudos
LucD
Leadership
Leadership

This could be the remains of a VM that has been removed since then.

When the removal didn't include the "Delete from disk" some of the files are orphaned and left behind.


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

Sivaramsharmar
Enthusiast
Enthusiast

Thanks Lucd for all your support.

0 Kudos