Reset Built-In Admin Password on Azure Virtual Machine


We got to a scenario , where we forgot our Administrator password for Azure virtual machine and their is no other account to login now.

No Idea on how to proceed ! :-o 

Are we stumped ? No after some research we got to find a solution which made us to reset Azure VM Built-In Admin Password.

First Step is you need to have a power shell, with Windows Azure Power Shell Module installed.

Below Link shows how to Install Azure Power Shell modules


So get ready , once the power shell is installed follow the below steps:

  1. Open the Azure power shell , by running it as Administrator.
  2. Now type Get-Module Azure
  3. Then you need to connect to Azure account, so open Windows PowerShell ISE and run the following commands
    Set-ExecutionPolicy RemoteSigned
    Import-Module Azure
    Add-AzureAccount
  4. Now type you username and password of Azure Administrator \ CO-administrator account.
  5. Type below command to get list of your Azure subscriptions if you have many.
    Get-AzureSubscription | Format-Table –Property SubscriptionName
  6. Run the following command by entering your subscription name.
    $subscription = “ENTER YOUR SUBSCRIPTION NAME HERE”
    Select-AzureSubscription –Default $subscription
  7. Now you need to enter below command , to get a prompt for credentials to which you would like to reset the built-in administrator account of a virtual machine.
    $adminCredentials = Get-Credential -Message "Enter new Admin credentials"
  8. Last but now least, run the following snippet to get the account reset.
    (Get-AzureVM) |
    Where-Object -Property Status -EQ "ReadyRole" |
    Select-Object -Property Name, ServiceName |
    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"
        }
    }
Done, try login to your Azure Virtual Machine now. 

Success ? Great .

Comment on your experience.




5 comments:

  1. It proved to be Very helpful to me and I am sure to all the commentators here!
    jiofi 3 settings

    ReplyDelete
  2. Thanks for providing your information for more updates on Azure get touch with Azure Online Course Bangalore

    ReplyDelete
  3. Simple, short, in plain words! Thank you, author! You do great things! Also, take a look at a VM backup for next blog posts.

    ReplyDelete