VMware Cloud Community
narcissujsk
Contributor
Contributor

How to change the password of a VM by the vmware SDK

How to change the password of a VM by the vmware  SDK

Tags (1)
0 Kudos
1 Reply
AdrianTT
Enthusiast
Enthusiast

Hi,

If it’s a Windows Virtual Machine you could use PowerCLI cmdlet's to achieve this using the

Copy-VMGuestFile and Invoke-VMScript cmdlet's with a script similar to https://gallery.technet.microsoft.com/Reset-Local-Administrator-e3023c3a and a code similar to:

[string] $strvCenter = "labvc1.pigeonnuggets.com"

Connect-VIServer $strvCenter

$guestCredentials = Get-Credential # The Credentials for the guest machine

Copy-VMGuestFile -Source c:\_admin\PasswordReset.ps1 -Destination c:\temp\PasswordReset.ps1 -VM VM -LocalToGuest -GuestCredential $guestCredentials

$ResetPassword = (Invoke-VMScript -VM $vm -ScriptText ".\c:\temp\PasswordReset.ps1 -newpassword XXXXXXXXX" -GuestCredential $guestCredentials -WarningAction SilentlyContinue).ScriptOutput

Kind regards,

Adrian

Please consider marking this answer "correct" or "helpful" if you think your query have been answered correctly. Cheers,
0 Kudos