Microsoft Azure VMs have made a huge impact on our ability to quickly ramp up and ramp down development environments for our clients’ projects. Recently, we ran into a situation where the local admin password expired and we lost the ability to RDP in. Unfortunately, using the new Azure Portal, there is not a straightforward way to reset the password and regain control of the account. Ironically, if it had been what Microsoft calls a “Classic VM”, this would have taken mere seconds in the old portal. To my dismay, the “Reset Password” area in the new portal has a “coming soon” message. So, we had to find a different approach.
Some googling uncovered that changing a VM account password is possible using PowerShell. However, after reviewing and attempting the protocols in several links, nothing seemed to work (links below in case they might work for you). I was able to follow the patterns used in those references along with some navigating through MSDN to find that the new Resource Manager version of the PowerShell scripts is far simpler.
Here are the steps:
Setup Azure PowerShell
- Download and run the Azure PowerShell setup from here
- In Azure PowerShell, Run the scripts to install the necessary modules from the Gallery (from the link in step 1)
# Install the Azure Resource Manager modules from the PowerShell Gallery
Install-Module AzureRM
Install-AzureRM
# Install the Azure Service Management module from the PowerShell Gallery
Install-Module Azure
# Import AzureRM modules for the given version manifest in the AzureRM module
Import-AzureRM
# Import Azure Service Management module
Import-Module Azure
From https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/
Connect to Azure and Reset the VM Password
1. Run the below script and login using your Azure account credentials
Login-azurermaccount
2. To link to your subscription, run the below script, filling in your subscription name (“Visual Studio Enterprise with MSDN” for example). Note: I administer multiple subscriptions with the same name and ran into an ambiguity issue. I found the easiest solution was to rename the subscription I wanted to work with. Steps to do that are in the Appendix.
Get-AzureRmSubscription -SubscriptionName “<subscriptionname>” | Select-AzureRmSubscription
3. Verify which VMs are in your subscription. This will ensure you have correctly selected your subscription and provide the details you’ll need for all VMs there.
Get-AzurermVM
4. Issue the below command to reset an account password. Note: if you provide a username that doesn’t already exist, it will provision a new account with that name/password. Simply replace what I have marked inside of <> with your values. Most should be able to be found in the results from your Get-AzureRMVM command. In my case the VMName and Name values were the same.
Set-AzurermVMAccessExtension -UserName “<adminusername>” -Password “<newpassword>” -ResourceGroupName “<VMResourceGroupName>” -VMName “<VMName>” -Name “<UsuallySameAsVMName>”
You should now be able to RDP into your VM using the account and password you specified.
Appendix A: Renaming Your Azure Subscription
1. Login to portal.Azure.com
2. Click on Subscriptions in the left Pane
3. Click on the subscription you’d like to change the name of
4. In the fly-out details to the right, click the “Manage” button at the top under the subscription name (this should open a new window to account.windowsazure.com)
5. Click the “Edit Subscription Details” link in the right section
6. Change the Subscription Name in the dialog box to the new name of your choosing and click the green check to save it
Appendix B: Links and References
Installing and configuring Microsoft Azure PowerShell:
https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/
Original Microsoft article on how to reset a VM password:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-reset-password/
Another useful blog I found describing how to change a password:
MDN reference for Resource Manager cmdlets (including login-azurermaccount, get-azurermsubscription, get-azurermvm, and set-azurermvmaccessextension):
https://msdn.microsoft.com/en-us/library/mt125356.aspx