#requires -version 3.0 Function Get-VMMemoryReport { <# .Synopsis Get a VM memory report .Description This command gets memory settings for a given Hyper-V virtual machine. All memory values are in MB. The command requires the Hyper-V module. .Parameter Name The name of the virtual machine or a Hyper-V virtual machine object. This parameter has an alias of "VM" .Parameter Computername The name of the Hyper-V server to query. The default is the local host. .Example PS C:\> Get-VM chi-win8 | Get-VMMemoryReport Name : CHI-Win8 Dynamic : True Assigned : 873 Demand : 724 Startup : 768 Minimum : 512 Maximum : 1048576 Buffer : 20 Priority : 50 Get a memory report for a single virtual machine. .Example PS C:\> Get-VM | where {$_.state -eq 'running'} | Get-VMMemoryReport | format-table -autosize Get a memory report for all running virtual machines formatted as a table. .Example PS C:\> get-content d:\MyVMs.txt | get-vmmemoryreport | Export-CSV c:\work\VMMemReport.csv -notypeinformation Get virtual machine names from the text file MyVMs.txt and pipe them to Get-VMMemoryReport. The results are then exported to a CSV file. .Example PS C:\> get-vm | get-vmmemoryreport | Sort Maximum | convertto-html -title "VM Memory Report" -css c:\scripts\blue.css -PreContent "

Hyper-V Memory Report

" -PostContent "
An assigned value of 0 means the virtual machine is not running." | out-file c:\work\vmmemreport.htm Get a memory report for all virtual machines, sorted on the maximum memory property. This command then creates an HTML report. .Link Get-VM Get-VMMemory .Inputs Strings .Outputs Custom object #> [cmdletbinding()] Param( [Parameter(Position=0,Mandatory=$True,HelpMessage="Enter a VM", ValueFromPipeline=$True)] [alias("VM")] [object]$Name, [ValidateNotNullorEmpty()] [string]$Computername=$env:COMPUTERNAME ) Process { if ($Name -is [String]) { Try { $Name = Get-VM -name $Name -ComputerName $computername -ErrorAction Stop } Catch { Write-Warning "Failed to find VM $vm on $computername" Return } } #if elseif ($name -isnot [Microsoft.HyperV.PowerShell.VirtualMachine]) { Write-Warning "You did not pass a string or a VM object" Return } #get memory values $memorysettings = Get-VMMemory -VMName $Name.name -ComputerName $Computername #all values are in MB $hash=[ordered]@{ Name = $Name.Name Dynamic = $Name.DynamicMemoryEnabled Assigned = $Name.MemoryAssigned/1MB Demand = $Name.MemoryDemand/1MB Startup = $Name.MemoryStartup/1MB Minimum = $Name.MemoryMinimum/1MB Maximum = $Name.MemoryMaximum/1MB Buffer = $memorysettings.buffer Priority = $memorysettings.priority } #write the new object to the pipeline New-Object -TypeName PSObject -Property $hash } #process } #end Get-VMMemoryReport