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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#Requires -Modules ImportExcel
#Requires -RunAsAdministrator
$node = get-storagenode -Name ([System.Net.Dns]::GetHostByName(($env:computerName))).Hostname
$reportPath = $env:TEMP
#### DONT EDIT BELOW ####
### Populate Physical Disks from Node
if($node.count -gt 1){
$phydisks = @()
foreach($i in $node){
$phydisks += Get-PhysicalDisk -StorageNode $i
}
}
else{
$phydisks = Get-PhysicalDisk -StorageNode $node
}
### Get disks from DISKPART
$dpscript = New-TemporaryFile
Add-Content $dpscript "LIST VOLUME"
$dpvols = & diskpart /s $dpscript.FullName
$line = 8
$dpdata = @()
do{
if(($dpvols[$line] -split " ").Where({$_ -ne ""})[0] -eq'Volume'){
$vol = ($dpvols[$line] -split " ").Where({$_ -ne ""})
if(!($dpvols[($line + 1)].StartsWith(' Volume')) -and $dpvols[($line + 1)].Length -gt 0 ){
$mount = $dpvols[($line + 1)]
$line += 2
}
else{
$mount = ($vol -split " ").Where({$_ -ne ""})[2]
$line += 1
}
$dpscript = New-TemporaryFile
Add-Content $dpscript "SELECT $($vol[0]) $($vol[1])"
Add-Content $dpscript "DETAIL VOLUME"
$detail = & diskpart /s $dpscript.FullName
$volType = $vol[5]
$volSize = "$($vol[6])$($vol[7])"
if($vol.count -eq 7){
$volType = $vol[4]
"$($vol[5])$($vol[6])"
}
foreach($disk in $detail | ? { $_ -like "*Disk [0-9]*"}){
$disk = ($disk -split " ").Where({$_ -ne ""})
$diskID = $disk[1]
if($disk[0] -eq "*"){
$diskID = $disk[2]
}
$dpdata += [pscustomobject]@{
Volume = $vol[1]
Name = $vol[2]
Mount = $mount.Trim(" ")
Type = $vol[4]
Size = "$($vol[5])$($vol[6])"
DiskId = $diskID
}
}
}
else {
break
}
}While ($true)
### MAP together info with WMI
$diskInfo = @()
$wmiDisks = Get-WmiObject win32_diskdrive
Foreach($wmiDisk in $wmiDisks){
$deviceID = $wmiDisk.DeviceID.Trim("\\.\PHYSICALDRIVE")
$type = $wmiDisk.caption
$sn = $wmiDisk.serialnumber
$phDisk = $phydisks | ? { $_.deviceid -eq $deviceID }
$lun = ""
if($phDisk){
$lun = ($phDisk.PhysicalLocation -split "LUN ")[1]
}
$virtualID = ""
$virtualDiskName = ""
$columns = ""
$mount = ($dpdata | ? {$_.DiskId -eq $deviceID}).Mount
if($sn){
$virtualDisk = Get-VirtualDisk | ? {$_.ObjectId -like "*$($sn)*" }
$physicalDisk = $virtualDisk | Get-PhysicalDisk
$virtualID = $wmiDisk.DeviceID.Trim("\\.\PHYSICALDRIVE")
$deviceID = $physicalDisk.DeviceId
$virtualDiskName = $virtualDisk.FriendlyName
$mount = ($dpdata | ? {$_.DiskId -eq $virtualID}).Mount
$columns = $virtualDisk.NumberOfColumns
foreach($pdrive in $physicalDisk){
$deviceID = $pdrive.DeviceId
$phDisk = $phydisks | ? { $_.deviceid -eq $deviceID }
if($phDisk){
$lun = ($phDisk.PhysicalLocation -split "LUN ")[1]
}
$diskInfo += [pscustomobject]@{
DeviceID = $deviceID
LUN = $lun
Type = $type
SerialNumber = $sn
VirtualID = $virtualID
VirtualDiskName = $virtualDiskName
Columns = $columns
Mount = $mount
}
}
}
else {
$diskInfo += [pscustomobject]@{
DeviceID = $deviceID
LUN = $lun
Type = $type
SerialNumber = $sn
VirtualID = $virtualID
VirtualDiskName = $virtualDiskName
Columns = $columns
Mount = $mount
}
}
}
#Export Report
$fdate = (Get-date).ToString("yyyyMMdd")
$dpdata | Export-Excel "$reportPath\DiskReport_$fdate.xlsx" -AutoSize -TableName "DISKPART_INFO" -WorksheetName 'DISKPART INFO' -Title "DISKPART INFO"
$diskInfo | Export-Excel "$reportPath\DiskReport_$fdate.xlsx" -AutoSize -TableName "VOLUME_INFO" -WorksheetName 'VOLUME INFO' -Title "VOLUME INFO"
Write-host "Report saved to $reportPath\DiskReport_$fdate.xlsx"
|