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
139
140
|
# Naive parsing of the output of rpowermt for PowerPath/VE against CLARiiON and Symmetrix devices
param (
$fileName = "esx001_luninfo.txt"
)
# Easily re-usable data object
Function LunInfo {
"" | Select-Object "PseudoName", "ArrayType", "ArrayID", "LunID", "LunLabel"
}
# Generic dispatcher to more detailed parsers
Function Parse-LunInfo {
param (
[String[]]$info
)
if ($info.Length -lt 2) {
throw "Insufficient rpowermt input to determine device type."
}
switch -regex ($info[1]) {
'^CLARiiON' {Parse-CLARiiONInfo $info}
'^Symmetrix' {Parse-SymmetrixInfo $info}
default {throw "Unhandled device type."}
}
}
# Parse CLARiiON lun information
Function Parse-CLARiiONInfo {
param (
[String[]]$info
)
if ($info.Length -lt 3) {
throw "Insufficient data for the CLARiiON data block."
}
$lunInfo = LunInfo
$lunInfo.ArrayType = "CLARiiON"
# Parse the first line
if ($info[0] -match 'Pseudo name=(?<Name>\w+\d+)') {
$lunInfo.PseudoName = $Matches["Name"]
}
else {
throw "Invalid pseudo name data for CLARiiON."
}
# Parse the second line
if ($info[1] -match 'CLARiiON ID=(?<ArrayId>[\w\d]+)') {
$lunInfo.ArrayID = $Matches["ArrayId"]
}
else {
throw "Invalid CLARiiON ID line."
}
# Third line
if ($info[2] -match 'Standard UID=(?<LunID>.+)\s\[(?<LunLabel>.*)\]') {
$lunInfo.LunID = $Matches["LunID"]
$lunInfo.LunLabel = $Matches["LunLabel"]
}
else {
throw "Invalid CLARiiON Standard UID line."
}
$lunInfo
}
# Parse Symmetrix LUN information
Function Parse-SymmetrixInfo {
param (
[String[]]$info
)
if ($info.Length -lt 4) {
throw "Insufficient data for the CLARiiON data block."
}
$lunInfo = LunInfo
$lunInfo.ArrayType = "Symmetrix"
# Parse the first line
if ($info[0] -match 'Pseudo name=(?<Name>\w+\d+)') {
$lunInfo.PseudoName = $Matches["Name"]
}
else {
throw "Invalid pseudo name data for Symmetrix."
}
# Parse the second line
if ($info[1] -match 'Symmetrix ID=(?<ArrayId>\d+)') {
$lunInfo.ArrayID = $Matches["ArrayId"]
}
else {
throw "Invalid Symmetrix ID line."
}
# Third line
if ($info[2] -match 'Logical device ID=(?<LunLabel>[\w\d]+)') {
$lunInfo.LunLabel = $Matches["LunLabel"]
}
else {
throw "Invalid Symmetrix logical device ID line."
}
# Fourth line
if ($info[3] -match 'Standard UID=(?<LunID>naa\.\d+)') {
$lunInfo.LunID = $Matches["LunID"]
}
else {
throw "Invalid CLARiiON Standard UID line."
}
$lunInfo
}
$fileData = Get-Content $fileName
$elementData = @()
# Assuming information blocks are data are separated by a blank line.
foreach ($line in $fileData) {
if ($line -eq "") {
if ($elementData.Length -gt 0) {
Parse-LunInfo $elementData
$elementData = @()
}
}
else {
$elementData += $line
}
}
# Catch anything leftover at the end.
if ($elementData.Length -gt 0) {
Parse-LunInfo $elementData
}
|