Created
June 8, 2015 19:20
-
-
Save ploegert/7000ca8a4eb21f88b866 to your computer and use it in GitHub Desktop.
Reset Azure VM User Password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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