Posted in
Virtual Machine Manager,
Windows Powershell,
Windows Server |
1 Comment | 3,990 views | 25/08/2012 22:01
I’m re-coding PoSHStats for Cluster support. Currently it just supports standalone hosts, but i have to extend that support for cluster environments. So while i’m playing with Powershell, I want to add some of my codes.
Getting Hyper-V hostname:
$Hostname = gc env:computername |
$Hostname = gc env:computername
Getting Cluster name of your Hyper-V host:
$ClusterName = (Get-Cluster | Get-ClusterNode | where Name -eq $Hostname).Cluster.Name |
$ClusterName = (Get-Cluster | Get-ClusterNode | where Name -eq $Hostname).Cluster.Name
Even better one for Hyper-V specifically:
$ClusterName = (@(Get-Cluster | Get-ClusterNode | where Name -eq $Hostname | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name |
$ClusterName = (@(Get-Cluster | Get-ClusterNode | where Name -eq $Hostname | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name
Also I see that this doesn’t work as expected on PowerShell v3, so don’t use something like this:
$ClusterName = @(Get-Cluster | Get-ClusterNode | where Name -eq $Hostname | Get-ClusterGroup | where GroupType -eq "VirtualMachine").Cluster.Name[0] |
$ClusterName = @(Get-Cluster | Get-ClusterNode | where Name -eq $Hostname | Get-ClusterGroup | where GroupType -eq "VirtualMachine").Cluster.Name[0]
Getting all clustered virtual machines:
$VMs = Get-Cluster $ClusterName | Get-ClusterGroup | Where GroupType -eq "VirtualMachine" | Get-VM |
$VMs = Get-Cluster $ClusterName | Get-ClusterGroup | Where GroupType -eq "VirtualMachine" | Get-VM
Also you can extend your query for resource monitoring:
$VMs = Get-Cluster -Name $ClusterName | Get-ClusterGroup | Where GroupType -eq "VirtualMachine" | Get-VM | where ResourceMeteringEnabled -eq $True | Measure-VM |
$VMs = Get-Cluster -Name $ClusterName | Get-ClusterGroup | Where GroupType -eq "VirtualMachine" | Get-VM | where ResourceMeteringEnabled -eq $True | Measure-VM
Getting free space of Cluster Shared Volume:
1
2
3
| $CSVVolume = "Volume1"
$CSVDisk = Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Where FriendlyVolumeName -match "$CSVVolume"
[int]$HostDiskDriveFreeSpace = ([math]::round((($CSVDisk | Select -Expand Partition).FreeSpace / 1GB), 0)) |
$CSVVolume = "Volume1"
$CSVDisk = Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Where FriendlyVolumeName -match "$CSVVolume"
[int]$HostDiskDriveFreeSpace = ([math]::round((($CSVDisk | Select -Expand Partition).FreeSpace / 1GB), 0))
Getting total disk space of Cluster Shared Volume:
1
2
3
| $CSVVolume = "Volume1"
$CSVDisk = Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Where FriendlyVolumeName -match "$CSVVolume"
[int]$HostDiskSpace = ([math]::round((($CSVDisk | Select -Expand Partition).Size / 1GB), 0)) |
$CSVVolume = "Volume1"
$CSVDisk = Get-ClusterSharedVolume | Select -Expand SharedVolumeInfo | Where FriendlyVolumeName -match "$CSVVolume"
[int]$HostDiskSpace = ([math]::round((($CSVDisk | Select -Expand Partition).Size / 1GB), 0))
I’ll share more next days, keep watching..