Azure PowerShell guide – how to reset Windows Server Username and Password

If you think you have forgotten the Windows Server VM username or password, you could simply reset the password with the PowerShell script below.

VmName is the virtual server name.

Location is the location in which the VM is hosted.

$ResourceGroupName = "server_"
$VmName = "windows"
$Location = "West Europe"

# Sets the current Subscription
$SubID = Get-AzureRmSubscription | Select-Object ID
$SubID = $SubID.Id.ToString();

Select-AzureRMSubscription -SubscriptionId $SubID
Set-AzureRmVMAccessExtension -ResourceGroupName $ResourceGroupName `
-Location $Location -VMName $VmName -Credential (get-credential) `
-typeHandlerVersion "2.0" -Name VMAccessAgent

Before resetting the password! Ensure that you have allowed the RDP port to the Server

You will be prompted to enter your email address.

If you go back to the terminal, you will have to enter the username and password.

If the account does not exist, Azure will create an administrator account ?

Pro tip: Look into Azure Bastion