VMware Cloud Community
arunrj
Enthusiast
Enthusiast

Getting the Virtual Machine Swapfile location using PowerCLI script

I have around 85 hosts for which I need to pull out a report which can show the VM swapfile location along with free space on the VMFS volumes set aside as SWAP datastore.


Is there a powercli script which can do this?


Tags (2)
0 Kudos
2 Replies
LucD
Leadership
Leadership

Try something like this

$dsTab = @{}
Get-Datastore | %{
  $dsTab[$_.Name] = $_.FreeSpaceGB
} Get-VM | %{   $ds = $_.ExtensionData.Layout.Swapfile.Split(']')[0].TrimStart('[')   $_ | Select Name,@{N="Swap DS";E={$ds}},@{N="Free GB";E={[math]::Round($dsTab[$ds],1)}} }

The script uses a hash tab to avoid having to do a Get-Datastore each time.


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

0 Kudos
mattandes
Enthusiast
Enthusiast

I know this is an old post but it proved useful to me the other day. As a result I created a function called Get-VMSwapInfo which was inspired by LucD's response that will output the VM's name, the name of it's swap file, the datastore it's located in, and how much space is left on that datastore. You can get the source and more info on my blog on this page. http://www.virtual-matt.net/2013/06/get-vm-swap-information/

Blog: http://www.virtual-matt.net
0 Kudos