Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reset-AzureVMUserPassword
Function Reset-AzureVMUserPassword {
param (
[String]
$VMName,
[String]
$ServiceName,
[PSCredential]
$Credential
)
try {
$VM = Get-AzureVM -ServiceName $ServiceName -Name $VMName
If ($VM.VM.ProvisionGuestAgent) {
Set-AzureVMAccessExtension -VM $VM `
-UserName $Credential.UserName `
-Password $Credential.GetNetworkCredential().Password `
-ReferenceName "VMAccessAgent" |
Update-AzureVM
Restart-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name
}
}
catch {
Write-Error $_
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment