带有 .InstallProductKey 的 WMIMethodException [英] WMIMethodException with .InstallProductKey

查看:19
本文介绍了带有 .InstallProductKey 的 WMIMethodException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这是我的第一篇文章,所以如果我错误地将其发布在错误的位置,请告诉我.

First off, this is my first post, so if I incorrectly posted this in the wrong location, please let me know.

所以,我们想要完成的是构建一个可以放在我们的工作站映像上的 powershell 脚本,这样一旦我们的 Windows 10 机器完成映像,我们就可以单击一个 powershell 脚本,让它拉动钥匙从 BIOS,并自动激活它.话虽如此,以下是我们从各种来源汇总的脚本.

So, what we're trying to accomplish is building a powershell script that we can throw on our workstation image so that once our Windows 10 boxes are done imaging, that we can click on a powershell script, have it pull the key from the BIOS, and automagically activate it. That being said, here is the script that we've put together from various sources.

(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey | out-file c:\license.txt

$computer = gc env:computername

$key = get-content c:\license.txt

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

$service.InstallProductKey($key)        <--------THIS IS WHERE IT FAILS

$service.RefreshLicenseStatus()

<小时>

我们开始遇到 $service.InstallProductKey($key) 行上的问题.看来,无论我们如何尝试调用它,它都会始终失败并显示错误调用InstallProductKey"的异常".我什至用特定的激活密钥替换了变量 ($key),但它仍然失败并出现相同的错误.


We start running into the issues on the line $service.InstallProductKey($key). It seems, that no matter how we try to invoke that, it will consistently fail with the error "Exception calling "InstallProductKey"". I've even replaced the variable ($key) with the specific activation key, and it STILL fails with the same error.

我们将它部分输出到许可 txt 文件的原因是,我们可以验证该命令确实在提取产品密钥(它是).

The reason we have it outputting to a license txt file part way through is so that we can verify that the command is indeed pulling the product key (which it is).

此时,我不知道该去哪里.似乎人们以前曾尝试过这样做,但是,没有人真正用有效和/或无效的方法结束他们的发布.我无法想象这是不可能的,但我也不喜欢浪费比需要更多的时间,所以任何对这个问题有任何见解的人,我都会非常感激.

At this point, I'm not sure where to go. It seems that people have tried to do this before, however, nobody has really wrapped up their posting with what worked and/or what didn't. I can't imagine that this is impossible, but I'm also not fond of wasting anymore time than needed, so anybody that has any insight into this issue, I'd be very grateful.

我们已经让它在两台之前被激活、后来被停用的机器上工作,但是在新的机器上,它已经被新镜像并且还没有被激活,每次都会失败.

We've gotten it to work on two machines that were previously activated, and later deactivated, but on new machines that have been freshly imaged, and have yet to be activated, it will fail every time.

推荐答案

根据我的观察,有两点:

Two things as per my observation:

(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey | out-file c:\license.txt

我认为它不会为您的 license.txt 返回任何值.如果是,那么我希望您查看许可证密钥前后是否有空格.您可以在从文件中获取内容时使用 trim.

I don't think that it is returning any value to your license.txt. If yes, then I would like you to see if there is any space before and after the license key. You can use trim during getting the content from the file.

第二件事,当您从文件中获取内容时,请确保它没有分成多行.在这种情况下,您必须将其转换为像 [String]$key 这样的字符串,或者您可以为此调用 toString() 方法.

Second thing, when you are getting the content from the file make sure it is not separating into multiple lines. In that case, you have to cast it as string like [String]$key or you can call toString() method for this.

更重要的一件事是安装后刷新.

One more important thing is to refresh after the installation.

$service.RefreshLicenseStatus()

注意:确保您在提升模式下运行 shell.

Note: Make sure you are running the shell in elevated mode.

替代方法:尝试对值进行硬编码并查看结果

$key = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" # hardcode the key
$computer= "Computer01" # Hardcode the computer
$service = get-wmiObject -query "select * from SoftwareLicensingService" -computername $computer
$service.InstallProductKey($key)
$service.RefreshLicenseStatus()

有关进一步的事情,请发布确切的错误.希望它有帮助...!!!

For further thing ,please post the exact error. Hope it helps...!!!

这篇关于带有 .InstallProductKey 的 WMIMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆