Azure / HyperV – forgot the admin password

April 2015

I’ve spent an age on this, so worth recording. The earlier post (see below) is on reflection unnecessarily verbose. And if there is one takeaway from this… when you change the admin password through PowerShell Azure on your client, or at least away from the VM, it is: REBOOT THE VM AFTER YOU’VE CHANGED IT… because RDP or whatever will just dumbly say “no… no…. er.. no..”

AzureLoginFailed04

Once you have done that… reboot the VM – I sat there for a stupidly long time, thinking WTF before I resorted to pulling the plug.

Get-AzureVM -ServiceName "MyVm" -Name "MyVm" | Set-AzureVMAccessExtension -UserName "MyAdmin" -Password "MyPassword" | Update-AzureVM

This post also repeated some advice.

 (Previously…)

http://blogs.technet.com/b/keithmayer/archive/2014/06/26/microsoft-azure-virtual-machines-reset-forgotten-admin-password-with-windows-powershell.aspx

 Azure PowerShell Tools

And if you didn’t know (and I didn’t), the target=”_blank” in the section below opens a new window:

<a href=”http://www.windowsazure.com/en-us/downloads/&#8221; target=”_blank”>axxx</a>

Azure01

Azure02

Azure03

Azure04

Azure05

Azure06

Azure07

Azure08

May as well download the full PowerShell while I’m doing it:

Azure09

So reminding myself of the purpose of these downloads, I wanted to reset my Admin password. And the downloads are all very well, in that it is useful to have tools, but I want stuff that I can run at work, for tryouts. So in summary, fine for home use, are these tools.

Azure10Now of course the next challenge in Windows 8.1 is to discover exactly where these have been installed, assuming that’s how it works.

So I open up a new PS window, and type, as per the example above:

Azure11

OK – not there. So I do a Windows search (I preferred Windows 8 not 8.1 for this), and lots of stuff:

Azure12

OK, so I picked Microsoft Azure Command v2.3:

Azure13

PS C:\> Get-Module Azure

So more promising:

Azure14

so now Import-Module Azure

Lots of stuff…

Azure15

Still looking good when we do [Add-AzureAccount] (note I didn’t do the Remote-Signed option – this is Windows 8.1, and the remote is Windows Server 2012, so neither should need it).

Azure16

So having done that, it goes away for a few seconds, and returns with this:

Azure18

Get-AzureSubscription

Azure19

(July 2015 – Get-AzureSubscription – note some stuff has changed – perhaps some of the indicators where security holes?)

subsAz01

Other useful ones – list all my Azure VMs:

Azure20

In fact, for practical reasons, everything between setting the credentials and resetting the password needs to be done in the ISE, because there’s a script which is more than 1 line:

Azure21

$subscription = "Visual Studio Ultimate with MSDN"
 Select-AzureSubscription -Default $subscription
 $adminCredentials = Get-Credential -Message "My Credentials"
 Get-AzureVM

 (Get-AzureVM) |
Where-Object -Property Status -EQ "ReadyRole" |
Select-Object -Property Name, ServiceName |
Out-GridView -Title "Select a VM …" -PassThru |
ForEach-Object {
    $VM = Get-AzureVM -Name $_.Name -ServiceName $_.ServiceName
    If ($VM.VM.ProvisionGuestAgent) {
        Set-AzureVMAccessExtension -VM $VM `
            -UserName $adminCredentials.UserName `
            -Password $adminCredentials.GetNetworkCredential().Password `
            -ReferenceName "VMAccessAgent" |
        Update-AzureVM
        Restart-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name
    } else {
        Write-Output "$($VM.Name): VM Agent Not Installed"
    }
}

And it all works great, as shown by the fact I can finally get into my VM without needing to tear it down and start again:

Azure22

So, I’m in – job done.

I’ve used up £15 of credit evidently in 4 or 5 days of doing nothing. I guess the lesson is to shut down the VM using PowerShell, when not in use.
Azure23

Azure24
Looking for a way to shut down VMs using Azure PS, found this.

That means we can do this:

Stop-AzureVM -ServiceName "DennisCloud" -Name "DennisVSU81" -Force
That works:
Azure25
Proven by losing the connection in RDP:
Azure26
Start it up again:

Start-AzureVM -ServiceName "DennisCloud" -Name "DennisVSU81" 

Azure27
Not yet available so, evidently needs some heartbeat check. But it didn't take long, so in summary, that azure command works fine, ie:

Stop-AzureVM -ServiceName "DennisCloud" -Name "DennisVSU81" -Force
All works fine:
Azure28
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s