簡體   English   中英

powershell (Get-WmiObject win32_physicalmedia).serialnumber 輸出十六進制

[英]powershell (Get-WmiObject win32_physicalmedia).serialnumber output hex

當我使用(Get-WmiObject win32_physicalmedia).serialnumber ,輸出是十六進制的。 示例: 31323334353637383930 然后我使用了下面的代碼

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

輸出為: 1234567890 問題是1234567890不是序列號——真正的序列號是2143658709 我需要一個腳本來將數字$input "1234567890"交換為$output "214365768709"

這假定您的 SN 字符串是偶數個字符,並且實數只是反轉字符對。

$InString = '1234567890'

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

$OutString

輸出 = 2143658709

我認為這稱為“中端”格式,其中每兩個字節顛倒一次:中端

來自此處的帖子: Vista 中的 WMI Win32_PhysicalMedia SMART ID 和 7 權限

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM