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
  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.
    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" |
            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.



Post a Comment