[Azure Stack] Reset a VM Password

February 22, 2016 at 7:00 am in Azure Stack, Microsoft, TP1 by Florent

image

Today, I tried to connect to my VM, but I received the error message to the effect that my password is incorrect:

imageimage

I decided to reset it from the portal, but the feature is not yet implemented:

image

So, the only way is to do it through PowerShell. Be sure to have the VM Access extension installed. If you don’t have, install it with the following PowerShell script, by changing the first 3 variables and execute it:

# Add the Microsoft Azure Stack environment
[net.mail.mailaddress]$AadFullMailAddress="whitepaper@azurelabdvo.onmicrosoft.com"
$RGName = "Compute"
$vmName = "WS2012R2"
$AadTenantId=(Invoke-WebRequest -Uri (‘https://login.windows.net/’+($AadFullMailAddress.Host)+’/.well-known/openid-configuration’) -UseBasicParsing|ConvertFrom-Json).token_endpoint.Split(‘/’)[3]
# Configure the environment with the Add-AzureRmEnvironment cmdlt
Add-AzureRmEnvironment -Name ‘Azure Stack’ `
            -ActiveDirectoryEndpoint ("https://login.windows.net/$AadTenantId/") `
            -ActiveDirectoryServiceEndpointResourceId "https://azurestack.local-api/"`
            -ResourceManagerEndpoint ("https://api.azurestack.local/") `
            -GalleryEndpoint ("https://gallery.azurestack.local/") `
            -GraphEndpoint "https://graph.windows.net/"
# Authenticate a user to the environment (you will be prompted during authentication)
$privateEnv = Get-AzureRmEnvironment ‘Azure Stack’
$privateAzure = Add-AzureRmAccount -Environment $privateEnv -Verbose
Select-AzureRmProfile -Profile $privateAzure

$extensionName = "VMAccessAgent"
$publisher = "Microsoft.Compute"
$version = "2.0"
Set-AzureRmVMExtension -ExtensionName $extensionName -Publisher $publisher -Version $version -ExtensionType $extensionName -Location local -ResourceGroupName $RGName -VMName $vmName –Verbose

image

After few minutes, your extension is installed:

imageimage

You can now reset the VM Password. Execute the following script, with your account name:

$cred = Get-Credential "Florent" –Message "Name of the current account and the new password"
Set-AzureRmVMAccessExtension -ResourceGroupName $RGName -VMName $vmName -Name $extensionName -UserName $cred.GetNetworkCredential().Username -Password $cred.GetNetworkCredential().Password -Location local

image

After 2 minutes, the password reset is finished:

image

You can now connect with your new password:

image

image