Mahesh Velaga
Mahesh Velaga

Reputation: 21991

Automate first time password reset using PowerShell

I am creating a VM on the fly with PowerShell (on ESX with Windows Server 2012 R2). I have most of the automation pieces in place, but when it comes to resetting the Administrator password the first time we login to the VM after provisioning (as a part of windows security policy), I am having a hard time.

I have tried stuff like the following (which didn't work):

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

It fails by saying:

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

What can I try to fix this?

Upvotes: 0

Views: 447

Answers (1)

Bluecakes
Bluecakes

Reputation: 2149

This has worked for me remotely which is something that you can try:

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

If that doesnt work you may want to check on the security policy and see if the password matches the security policy, powershell errors can sometimes be incredibly bland.

Upvotes: 1

Related Questions