简体   繁体   中英

powershell (Get-WmiObject win32_physicalmedia).serialnumber output hex

When I used (Get-WmiObject win32_physicalmedia).serialnumber the output was in hex. Example: 31323334353637383930 . Then then I used the code below

$pass=""
$t=(Get-WmiObject win32_physicalmedia).serialnumber
$t -split '(.{2})' |%{ if ($_ -ne "") { $pass+=[CHAR]([CONVERT]::toint16("$_",16))  }}
write host $pass

The output was: 1234567890 . The problem is that 1234567890 is not the serial number -- the real serial number is 2143658709 . I need a script to swap the number $input "1234567890" to $output "214365768709" .

this presumes your SN string is an even number of characters, and that the real number simply reverses the character pairs.

$InString = '1234567890'

$OutString = ''
foreach ($Index in 0..($InString.Length / 2))
    {
    $CurPos = $Index * 2
    $OutString += $InString[$CurPos + 1] + $InString[$CurPos]
    }

$OutString

output = 2143658709

I think this is called "middle endian" format, where every two bytes are reversed: middle-endian

Coming from a post here: WMI Win32_PhysicalMedia SMART ID in Vista and 7 Permissions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM