使用PowerShell自动重置第一次密码

时间:2014-08-05 02:25:36

标签: powershell virtual-machine windows-server-2012 powercli

我正在使用PowerShell动态创建VM(在带有Windows Server 2012 R2的ESX上)。我有大多数自动化部件,但是当我们在配置后第一次登录VM时(作为Windows安全策略的一部分)重置管理员密码时,我很难。

我尝试过以下内容(这些内容无效):

[ADSI]$vmAccount="WinNT://$vmName/$vmUserName"
$vmAccount.ChangePassword($current, $new)

它失败了:

Exception calling "ChangePassword" with "2" argument(s): 
"The specified network password is not correct.

非常感谢任何指导我指向正确方向的帮助。

1 个答案:

答案 0 :(得分:1)

这对我有用,你可以尝试:

$comp = <computer>
$user = <Username here>
$pass = <New password here>
("WinNT://$comp/$user/").SetPassword($pass)

如果这不起作用,您可能需要检查安全策略并查看密码是否与安全策略匹配,PowerShell错误有时会非常乏味。