Home > PowerCLI, PowerShell, vSphere > PowerCLI: Convert PortWorldWideName or NodeWorldWideName to hexadecimal format.

PowerCLI: Convert PortWorldWideName or NodeWorldWideName to hexadecimal format.

If you output one of the fields of $VMHost.Config.StorageDevice.MultipathInfo.Lun[x].Path[x].Transport, you will get the output in standard decimal numbers.

This is different from what is used in SAN environment where they mostly use XX:XX:XX:XX:XX:XX:XX:XX where XX is a hexadecimal number.

 

Use the following code to convert from the decimal format to the hexadecimal SAN format:

[String] $lstrWWNNHex = "{0:x}" -f $NodeWorldWideName
[String] $lstrWWNNHexFormatted = ""
For ($i=0;$i -lt 8;$i++)
{
$lstrWWNNHexFormatted += "{0}:" -f $($lstrWWNNHex.SubString($i * 2, 2))
}
$lstrWWNNHexFormatted = $lstrWWNNHexFormatted.SubString(0, $lstrWWNNHexFormatted.Length - 1)

$NodeWorldWideName is the WWN generated by $VMHost.Config.StorageDevice.MultipathInfo.Lun[x].Path[x].Transport.NodeWorldWideName.  You can use the same for PortWorldWideName.

Advertisements
Categories: PowerCLI, PowerShell, vSphere
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: