Recovering a Lost Azure VM Admin Password
- Run Windows PowerShell ISE in administrator mode.
- Enter and run the following PowerShell cmdlets hitting enter after each line:
Set-ExecutionPolicy RemoteSigned
Import-Module Azure
Add-AzureAccount
- Once the login prompt appears, enter the same username and password used to activate your Microsoft Azure account.
- Enter and run the following cmdlet to confirming the name of your Microsoft Azure subscription needed for the next step:
Get-AzureSubscription | Format-Table -Property SubscriptionName
- Enter the following cmdlets to select the required Microsoft Azure subscription. Be sure to replace CANITPRO with the name of your Azure subscription:
$subscription = “CANITPRO”
Select-AzureSubscription –Default $subscription
- Run the following prompting for the credentials you’d like to reset the existing built-in local Admin user account to:
$adminCredentials = Get-Credential -Message "Enter new Admin credentials"
- You are then prompted with a dialog to enter user name and password (you can enter your existing user name as well)
- Enter and run the following cmdlet to reset the built-in local Admin credentials with the ones provided in the previous step:
Get-AzureVM |
Where-Object -Property Status -EQ "ReadyRole" |
Out-GridView -Title "Select a VM …" -PassThru |
ForEach-Object {
$VM = Get-AzureVM -Name $_.Name -ServiceName $_.ServiceName
If ($VM.VM.ProvisionGuestAgent) {
Set-AzureVMAccessExtension -VM $VM `
-UserName $adminCredentials.UserName `
-Password $adminCredentials.GetNetworkCredential().Password `
-ReferenceName "VMAccessAgent" |
Update-AzureVM
Restart-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name
} else {
Write-Output "$($VM.Name): VM Agent Not Installed"
}
}
-
Login into your Azure VM using your newly set local admin username and password.
Article credit to : Anthony Bartolo