Posted in
Windows Powershell,
Windows Server |
No Comment | 2,213 views | 28/02/2014 11:57
If you want to use FCAdapter WMI Class to see Physical and Virtual Port WWPNs, this function will make WWPNs readable.
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
| function ConvertTo-WWPN
{
<#
.SYNOPSIS
Converts WWPN Integer Array to WWPN
.EXAMPLE
ConvertTo-WWPN -WWPNArray (Get-WmiObject -Namespace "root\wmi" -Class MSFC_FCAdapterHBAAttributes).NodeWWN
.NOTES
Author: Yusuf Ozturk
Website: http://www.yusufozturk.info
Email: ysfozy[at]gmail.com
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'WWPN Array')]
$WWPNArray,
[Parameter(
Mandatory = $false,
HelpMessage = 'Debug Mode')]
[switch]$DebugMode = $false
)
# Enable Debug Mode
if ($DebugMode)
{
$DebugPreference = "Continue"
}
else
{
$ErrorActionPreference = "silentlycontinue"
}
# Clear Values
$WWPN = $Null;
$WWPNInt = $Null;
$WWPNIntArray = $Null;
$WWPNObjArray = $Null;
$CheckWWPNArray = $Null;
# Check WWPN Array
$CheckWWPNArray = $WWPNArray -as [int[]]
if ($CheckWWPNArray)
{
# Get Length
$Length = $WWPNArray.Length;
# Create WWPN Object Array
for ($WWPNInt = 0; $WWPNInt -lt $Length; $WWPNInt++)
{
[int[]]$WWPNIntArray = $WWPNIntArray + [int] $WWPNArray[$WWPNInt];
[Object[]]$WWPNObjArray = $WWPNObjArray + "{0:X}" -f $WWPNIntArray[$WWPNInt];
}
# Create WWPN Address
for($WWPNInt = 0; $WWPNInt -lt $Length; $WWPNInt++)
{
if ($WWPNObjArray[$WWPNInt].Length -eq 1)
{
$WWPN = $WWPN + "0" + $WWPNObjArray[$WWPNInt];
}
else
{
$WWPN = $WWPN + $WWPNObjArray[$WWPNInt];
}
if ($WWPNInt -lt $Length - 1)
{
$WWPN = $WWPN + ":"
}
if ($WWPN.Length -eq "23")
{
# Output WWPN
[String]$WWPN;
}
elseif ($WWPN.Length -eq "24")
{
# Fix WWPN Value
$WWPN = $WWPN.Substring(0,23)
# Output WWPN
[String]$WWPN;
# Clear WWPN
$WWPN = $Null;
}
}
}
} |
function ConvertTo-WWPN
{
<#
.SYNOPSIS
Converts WWPN Integer Array to WWPN
.EXAMPLE
ConvertTo-WWPN -WWPNArray (Get-WmiObject -Namespace "root\wmi" -Class MSFC_FCAdapterHBAAttributes).NodeWWN
.NOTES
Author: Yusuf Ozturk
Website: http://www.yusufozturk.info
Email: ysfozy[at]gmail.com
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'WWPN Array')]
$WWPNArray,
[Parameter(
Mandatory = $false,
HelpMessage = 'Debug Mode')]
[switch]$DebugMode = $false
)
# Enable Debug Mode
if ($DebugMode)
{
$DebugPreference = "Continue"
}
else
{
$ErrorActionPreference = "silentlycontinue"
}
# Clear Values
$WWPN = $Null;
$WWPNInt = $Null;
$WWPNIntArray = $Null;
$WWPNObjArray = $Null;
$CheckWWPNArray = $Null;
# Check WWPN Array
$CheckWWPNArray = $WWPNArray -as [int[]]
if ($CheckWWPNArray)
{
# Get Length
$Length = $WWPNArray.Length;
# Create WWPN Object Array
for ($WWPNInt = 0; $WWPNInt -lt $Length; $WWPNInt++)
{
[int[]]$WWPNIntArray = $WWPNIntArray + [int] $WWPNArray[$WWPNInt];
[Object[]]$WWPNObjArray = $WWPNObjArray + "{0:X}" -f $WWPNIntArray[$WWPNInt];
}
# Create WWPN Address
for($WWPNInt = 0; $WWPNInt -lt $Length; $WWPNInt++)
{
if ($WWPNObjArray[$WWPNInt].Length -eq 1)
{
$WWPN = $WWPN + "0" + $WWPNObjArray[$WWPNInt];
}
else
{
$WWPN = $WWPN + $WWPNObjArray[$WWPNInt];
}
if ($WWPNInt -lt $Length - 1)
{
$WWPN = $WWPN + ":"
}
if ($WWPN.Length -eq "23")
{
# Output WWPN
[String]$WWPN;
}
elseif ($WWPN.Length -eq "24")
{
# Fix WWPN Value
$WWPN = $WWPN.Substring(0,23)
# Output WWPN
[String]$WWPN;
# Clear WWPN
$WWPN = $Null;
}
}
}
}
You can test this function with following script:
ConvertTo-WWPN -WWPNArray (Get-WmiObject -Namespace "root\wmi" -Class MSFC_FCAdapterHBAAttributes).NodeWWN |
ConvertTo-WWPN -WWPNArray (Get-WmiObject -Namespace "root\wmi" -Class MSFC_FCAdapterHBAAttributes).NodeWWN
As a result, you will see WWPNs of FC Adapters.