Hi Team,
I am using Invoke-vmscript to chnage the password of a computer via powershell. My script worked and changed the password as well but at the end i am getting the error mentioned below. Attaching the script aswell.
Script:
$VMcreds = Get-credential
$computer = "mycomputer"
$user = "adminmycomputer"
$code = @'
$account = [ADSI]("WinNT://Computer/user")
$password = Convertto-securestring "newpassword" -asplaintext -force
$account.psbase.Invoke("setpassword", "$password")
'@
$code = $code -replace "computer" , "$computer"
$script = $code -replace "user" ,"$username"
Invoke-VMScript -VM $computer -ScriptType Powershell -ScriptText $script -GuestCredential $VMCreds
Error:
Invoke-VMScript : Invoke-VMScript Failed to authenticate with the guest operating system using the supplied credentials.
At line:204 char:13
+ Invoke-VMScript -VM $vmname -ScriptType Powershell -Scrip ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], InvalidGuestLogin
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_GetProcessOutputInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
I wanted to know how to resolve this error