PowerShell读取Windows产品密钥

之前大多数人可能用过VBS读取Windows产品密钥的VBS脚本,VBS脚本通常都比较隐晦、难懂,今天忙里偷闲,随手写了一个用于读取Windows产品密钥的PowerShell脚本。

代码如下:

        =====文件名:Get-WindowsProductKey.ps1=====
 Get-WindowsProductKey([]$computer)
{

$comments =@'

'@
$reg = [WMIClass] ( + $computer + )
$values = [byte[]]($reg.getbinaryvalue(2147483650,,).uvalue)
$lookup = [char[]](,,,,,,,,,,,,,,,,,,,,,,,)
$keyStartIndex = []52;
$keyEndIndex = []($keyStartIndex + 15);
$decodeLength = []29
$decodeStringLength = []15
$decodedChars =  char[] $decodeLength 
$hexPid =  System.Collections.ArrayList
 ($i = $keyStartIndex; $i  $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }
 ( $i = $decodeLength - 1; $i  0; $i--)
    {                
      (($i + 1)  6  0){$decodedChars[$i] = '&
     
       {
        $digitMapIndex = []0
         ($j = $decodeStringLength - 1; $j  0; $j--)
        {
            $byteValue = [](($digitMapIndex * []256)  [byte]$hexPid[$j]);
            $hexPid[$j] = [byte] ([math]::Floor($byteValue / 24));
            $digitMapIndex = $byteValue  24;
            $decodedChars[$i] = $lookup[$digitMapIndex];
         }
        }
     }
$STR =      
$decodedChars |  { $str+=$_}
$STR
}

Get-WindowsProductKey .

执行效果如下:

image 

作者: 付海军
出处:http://fuhj02.cnblogs.com
版权:本文版权归作者和博客园共有
转载:欢迎转载,为了保存作者的创作热情,请按要求【转载】,谢谢
要求:未经作者同意,必须保留此段声明;必须在文章中给出原文连接且保证内容完整!否则必究法律责任!
个人网站: http://www.fuhaijun.com/

转载于:https://www.cnblogs.com/fuhj02/p/3351172.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值