POWERSHELL的一个函数

也许有用的,

一个函数

function Get-SQLserverKey { param ($targets = ".") $hklm = 2147483650 $regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup" $regValue1 = "DigitalProductId" $regValue2 = "PatchLevel" $regValue3 = "Edition" Foreach ($target in $targets) { $productKey = $null $win32os = $null $wmi = [WMIClass]"\\$target\root\default:stdRegProv" $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue1) [string]$SQLver = $wmi.GetstringValue($hklm,$regPath,$regValue2).svalue [string]$SQLedition = $wmi.GetstringValue($hklm,$regPath,$regValue3).svalue $binArray = ($data.uValue)[52..66] $charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9" ## decrypt base24 encoded binary data For ($i = 24; $i -ge 0; $i--) { $k = 0 For ($j = 14; $j -ge 0; $j--) { $k = $k * 256 -bxor $binArray[$j] $binArray[$j] = [math]::truncate($k / 24) $k = $k % 24 } $productKey = $charsArray[$k] + $productKey If (($i % 5 -eq 0) -and ($i -ne 0)) { $productKey = "-" + $productKey } } $win32os = Get-WmiObject Win32_OperatingSystem -computer $target $obj = New-Object Object $obj | Add-Member Noteproperty Computer -value $target $obj | Add-Member Noteproperty OSCaption -value $win32os.Caption $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture $obj | Add-Member Noteproperty SQLver -value $SQLver $obj | Add-Member Noteproperty SQLedition -value $SQLedition $obj | Add-Member Noteproperty ProductKey -value $productkey $obj } } Get-SQLserverKey


要注意的是,SERVERNAME,而不是SERVERNAME\INSTANCE.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值