If you forget the password for a virtual machine on Azure, you can easily reset it or create a new local administrator account by using PowerShell quite easily like I described in one of my previous articles. But if that virtual machine happens to be an Active Directory Domain Controller (like it was for me) you are in trouble. You won’t be able to reset the password, or create a new local administrator using the Set-AzureRmVMAccessExtension cmdlet.

If you try to run the cmdlet you will see an error like this saying VM Access Extension does not support Domain Controller.

1-not-allowed-to-add-access-extension.PNG

And if you check the Azure Portal and go to the extensions for the VM you will see that the extension provisioning failed for the Micorsoft.Compute.VMAccessAgent

2-removing-vm-extension.png

But there is a way you can get around this. The workaround is to use Net commands and Custom Script Extension in Azure Virtual Machines. Let’s see how it is done. It’s quite easy.

Resetting A Forgotten Password.

To reset the password for a known user, add the following command to a PowerShell script and save it.

This will reset the password of the existing user to the new password you added to the script.

Creating A New Local Administrator

To create a new Local Administrator, add the following commands to the PowerShell script and save it.

This script will first create a new user with the given username and the password. /add switch signifies creating a new user. Then the newly created user needs to be added to the Administrators Local Group. Again /add switch signifies adding a new entry to the Administrators Local Group.

 

Creating the Custom Script Extension

Once you created the script you need, the next step is to execute it in the Virtual Machine. To do that, login to the Azure Portal and navigate to the Virtual Machine that is the Domain Controller. In the Extensions section click on the Add button to add a new extension.

3-add-new-custom-script-extension.PNG

In the blade you can select the Custom Script Extension from the list of available extensions. And the click Create to create the custom script extension.

4-upload-powershell-script.PNG

In the Install Extension blade, upload the PowerShell script that we just created and click on Ok to install the extension. After a short while the extension will show up in the list of installed Extensions.

5-custom-script-extension-success.PNG

Click on the Extension to see the provisioning details and make sure that the provisioning was successful. If it failed, you can see the logs for the error messages in this blade as well. But if it’s successful, you can now use the newly created user to login to your Domain Controller Virtual Machine using RDP.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s