VMware Cloud Community
Developer_PK
Enthusiast
Enthusiast
Jump to solution

Invoke-vmscript shows error after changing the password.

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect this is normal, you change the password, so the credentials you passed to Invoke-VMScript are not valid anymore.

I normally use a scheduled task inside the Guest OS to make such changes.
The scheduled task is scheduled a minute or so in the future, which gives the Invoke-VMScript ample time to return.
As a test, you can after a couple of minutes, launch a new Ibvoke-VMScript with the new password to validate the password change succeeded.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect this is normal, you change the password, so the credentials you passed to Invoke-VMScript are not valid anymore.

I normally use a scheduled task inside the Guest OS to make such changes.
The scheduled task is scheduled a minute or so in the future, which gives the Invoke-VMScript ample time to return.
As a test, you can after a couple of minutes, launch a new Ibvoke-VMScript with the new password to validate the password change succeeded.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Developer_PK
Enthusiast
Enthusiast
Jump to solution

Thanks for the Help @LucD 

Reply
0 Kudos