虚位以待(AD)
虚位以待(AD)
首页 > 脚本专栏 > Powershell > PowerShell中获取Windows系统序列号的脚本分享

PowerShell中获取Windows系统序列号的脚本分享
类别:Powershell   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了PowerShell中获取Windows系统序列号的脚本分享,本文方法是读取注册表中的信息,然后处理成序列号输出,需要的朋友可以参考下

windows序列号可以直接在注册表中读取,PowerShell要做的只是读出数据后稍作处理,让它更像一个序列号。

复制代码 代码如下:

function Get-ProductKey {   
    $map="BCDFGHJKMPQRTVWXY2346789"
    $value = (get-itemproperty "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion").digitalproductid[0x34..0x42] 
    $ProductKey = "" 
    for ($i = 24; $i -ge 0; $i--) {
      $r = 0
      for ($j = 14; $j -ge 0; $j--) {
        $r = ($r * 256) -bxor $value[$j]
        $value[$j] = [math]::Floor([double]($r/24))
        $r = $r % 24
      }
      $ProductKey = $map[$r] + $ProductKey
      if (($i % 5) -eq 0 -and $i -ne 0) {
        $ProductKey = "-" + $ProductKey
      }
    }
    $ProductKey
}

输出结果为:

复制代码 代码如下:

PS> Get-ProductKey
VKTXG-GXXY3-W97QP-GP4PV-XXXXX

相关热词搜索: PowerShell 获取Windows系统序列号