Azure CLI 2.0: Reset / Change Azure VM Password 1

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#
Azure CLI 2.0: Reset / Change Azure VM Password 2

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.

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

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.

Microsoft MVP

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
HashiCorp Ambassador Microsoft Certified Trainer (MCT) Microsoft Certified: Azure Solutions Architect