search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Getting Passthrough Disk Reports from Hyper-V Clusters via PowerShell
Posted in Windows Powershell, Windows Server | No Comment | 2,958 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
		}
	}
}

You need to add your clusters into Clusters.txt file.



Leave a Reply