Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using WMI to find out what my WWN (World Wide Name) is for my port on an HBA card. I can get the WWN back but it is contained as an 8 byte array. I would like to convert this byte array into a string of 16 hex digits for easy display.

This is the query I am using to print out each number in its own line. Is there a way to convert this to have the 8 lines combined onto a single line?

gwmi -namespace root\wmi -class MSFC_FibrePortNPIVAttributes | select -expand WWPN | foreach { $_.ToString("X2") }

I think the following can be used to test with just the byte data but I'm still new to PowerShell.

[byte[]] 1,2,3,4,5,6,7,8 | foreach { $_.ToString("X2") }
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here are a few ways (I'm sure there are others):

[byte[]](1,2,3,4,5,6,7,8) | foreach { $string = $string + $_.ToString("X2") }
Write-Output $string

or

-join ([byte[]](1,2,3,4,5,6,7,8) |  foreach {$_.ToString("X2") } )

or

([byte[]](1,2,3,4,5,6,7,8) |  foreach { $_.ToString("X2") }) -join ""

Output for each of the above:

0102030405060708
share|improve this answer
    
This lead me down the correct path. I ended up with the following command that does what I need. gwmi -namespace root\wmi -class MSFC_FibrePortNPIVAttributes | select WWPN | foreach {[array]::Reverse($_.WWPN); [BitConverter]::ToUInt64($_.WWPN, 0).ToString("X") } –  Jason Aug 31 '10 at 0:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.