I'm a BIG fan of Microsoft Azure. I'm also a BIG fan of dystopian novels. What have the two got in common? Nothing, AFAIK, although I'm sure some tenuous links could be found by the hard-of-sleeping...
Blimey, I'm off topic already... so, Microsoft Azure...
I'm an even BIGGER fan of remotely managing my Azure VMs from my laptop with PowerShell. In this post, I'm going to discuss what you need to do to achieve this.
First up, to manage your Azure subscription with PowerShell you'll need the Azure PowerShell module:
How to: Install Azure PowerShell
Next, you'll need to download and import your subscription's publishSettings file. This cmdlet helps you perform the necessary authentication and download:
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile
Now, check your subscription out:
Get-AzureSubscription
All done? Good. You can now run the Azure cmdlets against your subscription and control the VMs from the perspective of the virtual host, e.g. you can stop them, start them, interrogate them, provision more, etc.
Get-Command-ModuleAzure-Noun*vm*
- Obtain the thumbprint of the default WinRM certificate from a VM
- Use the thumbprint to export the correct Azure certificate to file
- Import this certifcate to my localmachine\root certificate store
Once done it's just a case of connecting to the appropriate URI with the right credentials and the PS Remoting method of your choice.
The detail...
Obtain the thumbprint of the default WinRM certificate from a VM
As there may be other certificates associated with this cloud service, we get the default WinRM cetficate thumbprint from a VM to use in the next step.
$WinRMCert= (Get-AzureVM-ServiceNamePoShCloud-NamePoShCloudDC01).VM.DefaultWinRMCertificateThumbprint
The thumbprint obtained in the previous step is used to identify and export the appropriate management certificate.
(Get-AzureCertificate-ServiceNamePoShCloud-Thumbprint$WinRMCert-ThumbprintAlgorithmsha1).Data |Out-File".\PoShCloud.cer"
Import-Certificate-FilePath".\PoShCloud.cer"-CertStoreLocation"Cert:\localmachine\root"
$WinRmUri=Get-AzureWinRMUri-ServiceNamePoShCloud-NamePoShCloudDC01
$Creds=Get-Credential
Invoke-Command-ConnectionUri $WinRmUri-Credential$Creds-ScriptBlock {Get-ADDomainController-Discover-ServicePrimaryDC}
Enter-PSSession-ConnectionUri$WinRmUri-Credential$Creds