You can reset the Remote Desktop Services or its administrator password fro a VM using portal. In this article we will see how it can be reset using PowerShell script.

Make sure that you have the latest PowerShell module installed and configured.

Use the below script to reset the password using AzureRm PowerShell module-

————————————————————————————————————————————————

#### Provide the subscription ID where the resource resides
$SubscriptionID = “bxxxxx-xx-xx-xxxxx-xxxxf”

#### Provide the resourcegroupname where the VM is created
$ResourcegroupName = “tres-rg-name”

#### Provide VM name
$Vm = “test-vm-namet”

#### Provide location of resource
$Location = “Australia East”

### login to azure portal
login-AzureRmAccount

#### set the subscription in case you have multiple subscriptions
Set-AzureRmContext -SubscriptionId $SubscriptionID

Set-AzureRMVMAccessExtension -ResourceGroupName $ResourcegroupName -Location $Location -VMName $Vm -Credential (get-credential) -typeHandlerVersion “2.0” -Name “enablevmaccess”

————————————————————————————————————————————————

When you run this script, it will ask to login to portal. Once validated, it will show small popup asking for username to login to VM and the new password to reset. Once entered, it will reset the password and show the results.

 

 

Use the below script to reset the password using Az PowerShell module-

————————————————————————————————————————————————

#### Provide the subscription ID where the resource resides
$SubscriptionID = “bxxxxx-xx-xx-xxxxx-xxxxf”

#### Provide the resourcegroupname where the VM is created
$ResourcegroupName = “tres-rg-name”

#### Provide VM name
$Vm = “test-vm-namet”

#### Provide location of resource
$Location = “Australia East”

### login to azure portal
$AzCred = Get-Credential
az login -u $AzCred.UserName -p $AzCred.GetNetworkCredential().Password

#### set the subscription in case you have multiple subscriptions
Select-AzSubscription -SubscriptionId $SubscriptionID

Set-AzVMAccessExtension -ResourceGroupName $ResourcegroupName -Location $Location -VMName $Vm -Credential (get-credential) -typeHandlerVersion “2.0” -Name “enablevmaccess”

————————————————————————————————————————————————