Hi Everyone -
I need to reset my local admin account password on some VMs, I came across this topic here https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-script-to-change-admin-password-for-all-VMs-windows/td-p/376957
The code seems to be working decent enough, my question is I am authenticating to the VMs with the same account I am resetting the password, so ultimately the password reset appears to work but the script is "failing" with failed to authenticate (Although the password is being reset)
Obviously this is not an ideal situation i was curious what other people are doing or if there is anything I can do better with the script.
$VMNames = @("vmname1")
$AdminUser = "AdminAccount"
foreach ($VMName in $VMNames) {
$VM = Get-VM -Name $VMName
$Cred = Get-Credential -Message "Enter the current password for $AdminUser on $VMName"
$ScriptBlock = {
$localadministrator = [adsi]("WinNT://./adminaccount, user")
$localadministrator.psbase.invoke("SetPassword", "MyNewPassword")
Write-Host "Password for $AdminUser has been reset on $($env:COMPUTERNAME)."
}
Invoke-VMScript -VM $VM -ScriptType PowerShell -ScriptText $ScriptBlock -GuestCredential $Cred
}
Thanks in advance