Well, here’s my first post for this Hyper-V Blog. I will start with a small one… but more is coming soon!
In this blog I will show you how you can view memory usage of virtual machine’s when you didn’t have a management tool available. We will query this information from a Hyper-V node itself. There’s a great way to do this: use PowerShell!
So first we login to the host and browse to a directory e.g. E:Install. In this directory we will create a file named memory.ps1 (ps1 is the extension for a PowerShell script). Then we open the created file and paste the following script into it:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import-module -name failoverclusters $nodes = get-clusternode | %{$_.name} “host,vm,OStype,OSver,totalmem,memsize,pagesize,freemem,freephys,pagefree” foreach ($n in $nodes) { $vms = gwmi -class msvm_computersystem -namespace “rootvirtualization” -computername $n $vms = $vms|?{$_.caption -ne “Hosting Computer System”}|%{$_.elementname} foreach ($v in $vms) { if ($v) { $st = gwmi -class win32_operatingsystem -namespace “rootcimv2″ -computername $v 2> $null if ($st) { $pageused = $st.freeVirtualMemory – $st.freePhysicalMemory $memsize = $st.totalvirtualmemorysize – $st.sizestoredinpagingfiles $n + “,” + $v + “,” + $st.Caption + “,” + $st.CSDVersion + “,” ` + $st.totalvirtualmemorysize + “,” + $memsize + “,” ` + $st.SizeStoredInPagingFiles + “,” + $st.freeVirtualMemory ` + “,” + $st.freePhysicalMemory + “,” + $pageused } } } } |
So we’ll save the change and exit the file. Next we’ll start Powershell, browse to the directory E:Install and execute the script and write the output to an output file named output.csv:
[image not preserved in the archive]
All information will be writen into the file Output.csv. And with the help of only PowerShell we get a nice overview of memory usage of the running virtual machines.
I hope this post is usefull for you!