It’s very easy to spin up a Virtual Machine (VM) in Microsoft Azure. You can do it through the Azure Portal or with scripting tools such as the Azure CLI, Azure PowerShell cmdlets, and even ARM Templates. When you provision the new VM you need to set an Administrator username and password for the VM. You will use these login credentials to connect to and manage the VM. However, there are time when you either need to 1) change the password periodically, or 2) reset the password if you may have forgotten what it was. Thankfully, Azure makes the task of changing the password for a VM extremely easy to do from the management of your Azure Subscription. It can be done easily enough through the UI of the Azure Portal, however there are times when scripting and automation are necessary to fit your workflow best. Below you’ll find the simple, easy to use command to change / reset the password for a VM running in Azure. Both Windows and Linux VMs work the same way!

Here’s the command to use for updating / changing the password for a Virtual Machine running in Microsoft Azure:

# command format
az vm user update
    -n {vm name}
    -g {resource group name}
    -u {username}
    -p {password}

# usage example
az vm user update
    -n Win16VM
    -g Win16VMGroup
    -u myuser
    -p CliRocks4#

Here’s a description of the parameters to pass into the “az sql server update” command:

-n / –name
The name of the Azure Virtual Machine.

-g / –resource-group
The name of the Azure Resource Group that contains the Azure Virtual Machine.

-u
The username for the user you want to reset the password for.

-p
The new password that you want to set.

This is a simple command, but can be very useful. Especially in time when you may have forgotten the password, or if you just want to automate the changing of the password in a large automation process.

Posted by Chris Pietschmann

Chris is a Microsoft MVP and has nearly 20 years of experience building enterprise systems both in the cloud and on-premises. He is also a Certified Azure Solutions Architect (both MCSD and MCSE), a trainer, and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

One Comment

  1. […] Azure CLI 2.0: Reset / Change Azure VM Password (Chris Pietschmann) […]

    Reply

Leave a Reply