There are a few ways to do it. First, you could just parse the output of the "lun serial -x" command with a regex like this:
PS C:\> (Invoke-NaSsh "lun serial -x /vol/testluns/lun1" ) -replace ".*(0x\w*).*", "`$1"
0x50344461685a634562587732
But not everybody is nuts about regexes, and the Invoke-NaSsh cmdlet doesn't work if you are using RPC. So the second method makes use of the fact that the "-x" hex representation is just the characters converted to ASCII hex. You can do the whole conversion in one line:
PS C:\> ((Get-NaLunSerialNumber /vol/testluns/lun1).ToCharArray() | % {([byte][char]$_).ToString("X2")}) -join ""
50344461685A634562587732
But that's a little unwieldy, especially if you want to reuse it later. So, I'd probably define a function that does that for you:
function ConvertTo-HexString([string]$input)
{
[byte[]]$bytes = $input.ToCharArray()
$hexBytes = $bytes | % {$_.ToString("X2")}
$hexBytes -join ""
}
PS C:\> Get-NaLunSerialNumber /vol/testluns/lun1 | ConvertTo-HexString
50344461685A634562587732
Then you can put that function in the top of your script. Or if it's something you want to use from the commandline everyday, you can put it in your PS profile (the path is in the $profile variable) and then restart PowerShell.