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.
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
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.
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
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.
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
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
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
Thanks Lucd for all your support.