Powershell one liners for Hyper-V

Few Powershell based OneLiners which I use frequently !


Identify the best node for placement with respect to memory utilization.

(Get-ClusterNode -cluster CLUSTERNAME |Select Name, @{L="VMCount";E={(Get-VM -ComputerName $_.name).count}},
@{L="AvailableMemory(GB)"; E={(Get-VMHOST $_.Name).MemoryCapacity/1GB-(Get-VM -ComputerName $_.name |Measure-Object MemoryAssigned -Sum).sum/1GB}}|Sort "AvailableMemory(GB)" -Descending)



PowerShell One Liner - MemoryUsage

PowerShell One Liner – MemoryUsage


CSV Usage Statistics


Get-ClusterSharedVolume -Cluster CLUSTERNAME| select -Expand SharedVolumeInfo |select FriendlyVolumeName, @{n="Capacity(GB)";e={$_.Partition.Size/1GB}}, @{n="FreeSpace(GB)";e={($_.Partition.Size -$_.Partition.UsedSpace)/1GB}} |Sort-Object "FreeSpace(GB)" |sort "FreeSpace(GB)" -Descending



CSV Stat

List all VMs in a Hyper-V Cluster


Get-ClusterNode -Cluster CLUSTERNAME |foreach {Get-VM -ComputerName $_.Name}



List all VMs in a cluster with Integration Service version

Get-ClusterNode -Cluster CLUSTERNAME |Foreach {Get-VM -ComputerName $_.name |select name, IntegrationServices



List all VMs in a cluster which got a SnapShot/CheckPoint


Get-ClusterNode -Cluster CLUSTERNAME |Foreach {Get-VM -ComputerName $_.name|Where {$_.ParentSnapshotId -ne $Null}}


List all VMs with DVD/CD information

Get-ClusterNode -Cluster CLUSTERNAME |Foreach {Get-VM -ComputerName $_.name |Get-VMDvdDrive}


Mounted DVD Information

Mounted DVD Information


List all Hyper-V related errors for the last 24 hours

Get-ClusterNode -Cluster CLUSTERNAME |Foreach {Get-WinEvent Microsoft-Windows-hyper-V-* -ComputerName $_.name|where {$_.TimeCreated -gt (Get-Date).AddDays(-1) -AND ($_.LevelDisplayName -eq "Error" -OR $_.LevelDisplayName -eq "Critical")}|Select Machinename, TimeCreated, LevelDisplayName, MEssage |FL}



More to come !