Posted in
Windows Powershell,
Windows Server |
No Comment | 2,961 views | 05/10/2014 15:21
You can use following script to get passthrough disk reports from Hyper-V Clusters:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| # Get Clusters
$Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
# Get Cluster Nodes
$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
Write-Host Working on $ClusterNode
# Clear PT Values
$PTDisks = $Null;
$DiskNumber = $Null;
# Get Passthrough Disks
$PTDisks = Get-VM -ComputerName $ClusterNode | Get-VMHardDiskDrive | Where Path -like Disk*
foreach ($PTDisk in $PTDisks)
{
# Get VM Name
$VMName = $PTDisk.VMName
Write-Host Working on $VMName
# Get Passthrough Disk Info
$PTInfo = $PTDisk.Path
$DiskNumber = $PTDisk.DiskNumber
$ControllerNumber = $PTDisk.ControllerNumber
$ControllerLocation = $PTDisk.ControllerLocation
$ControllerType = $PTDisk.ControllerType
Write-Host Working on Disk $DiskNumber
if (!$DiskNumber)
{
$DiskNumber = $PTInfo.Split(" ")[1]
}
# Get Disk Info
$DiskInfo = Get-WmiObject Win32_DiskDrive -ComputerName $ClusterNode | Where Index -eq $DiskNumber
$Model = $DiskInfo.Model
$Caption = $DiskInfo.Caption
$Signature = $DiskInfo.Signature
$Size = [math]::round($DiskInfo.Size / 1GB,0)
# Set Output
$Value = $VMName + ";" + $ClusterNode + ";" + $ControllerType + ";" + $ControllerNumber + ";" + $ControllerLocation + ";" + $DiskNumber + ";" + $Model + ";" + $Signature + ";" + $Size
# Informational Output
Add-Content -Value $Value -Path Output.txt
}
}
} |
# Get Clusters
$Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
# Get Cluster Nodes
$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
Write-Host Working on $ClusterNode
# Clear PT Values
$PTDisks = $Null;
$DiskNumber = $Null;
# Get Passthrough Disks
$PTDisks = Get-VM -ComputerName $ClusterNode | Get-VMHardDiskDrive | Where Path -like Disk*
foreach ($PTDisk in $PTDisks)
{
# Get VM Name
$VMName = $PTDisk.VMName
Write-Host Working on $VMName
# Get Passthrough Disk Info
$PTInfo = $PTDisk.Path
$DiskNumber = $PTDisk.DiskNumber
$ControllerNumber = $PTDisk.ControllerNumber
$ControllerLocation = $PTDisk.ControllerLocation
$ControllerType = $PTDisk.ControllerType
Write-Host Working on Disk $DiskNumber
if (!$DiskNumber)
{
$DiskNumber = $PTInfo.Split(" ")[1]
}
# Get Disk Info
$DiskInfo = Get-WmiObject Win32_DiskDrive -ComputerName $ClusterNode | Where Index -eq $DiskNumber
$Model = $DiskInfo.Model
$Caption = $DiskInfo.Caption
$Signature = $DiskInfo.Signature
$Size = [math]::round($DiskInfo.Size / 1GB,0)
# Set Output
$Value = $VMName + ";" + $ClusterNode + ";" + $ControllerType + ";" + $ControllerNumber + ";" + $ControllerLocation + ";" + $DiskNumber + ";" + $Model + ";" + $Signature + ";" + $Size
# Informational Output
Add-Content -Value $Value -Path Output.txt
}
}
}
You need to add your clusters into Clusters.txt file.
Posted in
Windows Powershell,
Windows Server |
No Comment | 3,706 views | 10/07/2014 15:43
You may need to see passthrough disk information from Hyper-V VMs on several clusters.
So you can use following 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| # Get Clusters
$Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
# Get Cluster Nodes
$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
# Clear PT Values
$PTDisks = $Null;
# Get Passthrough Disks
$PTDisks = Get-VM -ComputerName $ClusterNode | Get-VMHardDiskDrive | Where Path -like Disk*
if ($PTDisks)
{
# Get VM Name
$VMName = $PTDisks[0].VMName
# Informational Output
Write-Host Working on $VMName..
foreach ($PTDisk in $PTDisks)
{
# Get Passthrough Disk Info
$PTInfo = $PTDisk.Path
# Informational Output
Write-Host $PTInfo
}
# Informational Output
Write-Host " "
Write-Host " "
}
}
} |
# Get Clusters
$Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
# Get Cluster Nodes
$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
# Clear PT Values
$PTDisks = $Null;
# Get Passthrough Disks
$PTDisks = Get-VM -ComputerName $ClusterNode | Get-VMHardDiskDrive | Where Path -like Disk*
if ($PTDisks)
{
# Get VM Name
$VMName = $PTDisks[0].VMName
# Informational Output
Write-Host Working on $VMName..
foreach ($PTDisk in $PTDisks)
{
# Get Passthrough Disk Info
$PTInfo = $PTDisk.Path
# Informational Output
Write-Host $PTInfo
}
# Informational Output
Write-Host " "
Write-Host " "
}
}
}
That will give you disk information output. You should add all clusters names into Cluster.txt file.