Posted in
Virtual Machine Manager,
Windows Powershell,
Windows Server |
1 Comment | 3,571 views | 16/07/2013 09:23
You can get Cluster names from your Hyper-V host list with following PowerShell script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| # Prepare Cluster Array
$ClusterArray = New-Object System.Collections.ArrayList
$Servers = Get-Content -Path C:\Servers.txt
foreach ($Server in $Servers)
{
$VMHost = Get-VMHost -ComputerName $Server
$HyperVFQDN = $VMHost.FullyQualifiedDomainName
if ($VMHost)
{
$ClusterName = (@(Get-Cluster $Server | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name
if ($ClusterName)
{
$TestCluster = $ClusterArray.Contains("$ClusterName")
if ($TestCluster -ne $True)
{
# Update Cluster Array
$ClusterArray.Add("$ClusterName") | Out-Null
}
Write-Host $ClusterName
}
}
} |
# Prepare Cluster Array
$ClusterArray = New-Object System.Collections.ArrayList
$Servers = Get-Content -Path C:\Servers.txt
foreach ($Server in $Servers)
{
$VMHost = Get-VMHost -ComputerName $Server
$HyperVFQDN = $VMHost.FullyQualifiedDomainName
if ($VMHost)
{
$ClusterName = (@(Get-Cluster $Server | Get-ClusterGroup | where GroupType -eq "VirtualMachine") | Select-Object -First 1).Cluster.Name
if ($ClusterName)
{
$TestCluster = $ClusterArray.Contains("$ClusterName")
if ($TestCluster -ne $True)
{
# Update Cluster Array
$ClusterArray.Add("$ClusterName") | Out-Null
}
Write-Host $ClusterName
}
}
}
After that you can use your Cluster names to get CSV reports.