拉动OEM密钥并激活

时间:2016-07-08 15:34:02

标签: windows powershell mdt

我是Surface Pro 3和4的借阅和播种过程的微软合作伙伴。我们每天对数百台设备进行重新映像,并且遇到数字授权问题。我需要一种方法从设备中提取OEM密钥并使用该密钥强制激活。我试图通过powershell脚本来实现这一目标:

<StackLayout>
  <ListView>
    ...
  </ListView>
  <StackLayout Orientation="Horizontal">
    <Button ... />
    <Button ... />
    <Button ... />
  </StackLayout>
</StackLayout>

我收到错误:

$computer = gc env:computername

$key = (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey | Out-String


$service = get-wmiObject -query “select * from SoftwareLicensingService” -computername $computer

$service.InstallProductKey($key)

$service.RefreshLicenseStatus()

任何帮助都将受到赞赏,无论是修复此错误还是有更简单的方法来完成我正在做的事情。谢谢!

编辑:添加了异常陷阱,新错误

Exception calling "InstallProductKey" : ""
At line:7 char:1
+ $service.InstallProductKey((Get-WmiObject -query ‘select * from Softw ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WMIMethodException

1 个答案:

答案 0 :(得分:0)

尝试在$ key的末尾添加.Trim()

我的下面的代码有一个类似的问题,它引发了相同的错误 异常调用"InstallProductKey" : "" 原来$key正在返回键字符串+后面有一些空格。归功于 @elexis 。对此无处可寻。

$computer = gc env:computername
$key = (wmic path softwarelicensingservice get oa3xoriginalproductkey)[2].Trim() #<--The Trim is to remove the white space aftewards which causes an error
Write-Output $key

$service = get-wmiObject -query "select * from SoftwareLicensingService" -computername $computer
$service.InstallProductKey($key)
$service.RefreshLicenseStatus()