Skip to main content

Powershell | Modify password for user account inside GuestOS of a VM

Today I got this challenge and I did it in below way-

#Start here

$VC = Read-host "Enter your vCenter server name\IP "

Connect-VIServer $VC

$vmName = Read-host "Enter the target VM Name in vCenter "

$UN = read-host "Enter the target username "

$pswd = 'Password' #Enter password here which you want to set in '' mark

$Chpass = @"

`$securePswd = ConvertTo-SecureString -AsPlainText -String $pswd -Force

Get-LocalUser -Name $newUser | Set-LocalUser  -Password `$securePswd -Confirm:`$false

"@

Invoke-VMScript -VM TestVM -ScriptText $Chpass -GuestUser "$UN" -GuestPassword "Asdf@1234" -ScriptType Powershell | Select -ExpandProperty scriptoutput

#End here
Please note that -

"Asdf@1234" is existing password of the guestOS
In case any error, do let me know, will surely help you out




Thank you,
Team vCloudNotes

Comments

Popular posts from this blog

Network Migration | VLAN to VXLAN

NSX-T | Getting Started with PowerCLI

NSX-T | Security

Automate Power on Operations using PS