Using Remote Powershell with Windows Azure Virtual Machines
Update: I created a script which makes this a lot easier, you can find it in my next blog post (Script to automatically configuring Remote PowerShell for Windows Azure Virtual Machines on your machine).
Just before the weekend Scott Guthrie announced a few improvements to Virtual Networks, Virtual Machines and Cloud Services. One of these improvements was the support for Remote Powershell. This means that, when you create a Virtual Machine you can choose to enable Remote Powershell on that machine.
You can enable Remote Powershell by simply checking the box after creating your Virtual Machine (not that this option only shows if you're creating the Virtual Machine from the gallery):
After the machine has been created go to the Endpoints tab. There you'll see which port maps to the remote Powershell port. In my case this is port 54355:
Now simply start a new Powershell console on your machine and use the Enter-PSSession command (replace the hostname, the port and the username):
Enter-PSSession -ComputerName mymachine.cloudapp.net -Port 54355 -Credential sandrino -UseSSL
Now when you try to connect you will see the following error:
Enter-PSSession : Connecting to remote server myserver.cloudapp.net failed with the following error message : The server certificate on the destination computer (myserver.cloudapp.net:54355) has the following errors: The SSL certificate is signed by an unknown certificate authority. For more information, see the aboutRemoteTroubleshooting Help topic.
This is because Remote Powershell uses HTTPS and the certificate used for your Virtual Machine is a self signed certificate. To solve this open your browser and navigate to your VM and the public endpoint for Remote Powershell. In my case this would be:
Now since I didn't find the certificate button in IE10 (sometimes it shows, sometimes it doesn't) I used Chrome to get the certificate by clicking the little lock and then clicking the Certificate information link:
This will open the certificate. Go to the Details tab and choose Copy to File to save the file to disk. After that you'll need to open the certificate and choose to install it under Current User > Trusted Root Certification Authorities. Press Yes to continue and you're done.
After that simply reexecute the
Enter-PSSession command and you'll be prompted for the password. Enter your password and you'll be connected to your VM using Remote Powershell:
And if you're done, just type exit to leave the session.