Enabling PowerShell remoting to an Azure VM

Posted by on Feb 5, 2014 in Azure, Other

I recently had the need to run some PowerShell scripts against a new VM created in Windows Azure using PowerShell Remoting. I thought this would be a simple enough job (and in truth, it is), but you need to know a couple of things.
By default, PowerShell uses active directory to identify and authenticate users, but of course standalone Azure VM’s aren’t part of a domain. Therefore you’ll need to add the public IP address of the VM to the trusted hosts on your client.

From the Azure portal, open port 5985 for PowerShell (the portal should open 5986 by default). To do this, go to:

Virtual Machines > YOUR VM > Endpoints > ADD.

Complete the resultant dialog:

2014-02-07 08_57_30-Virtual machines - Windows Azure

2014-02-07 08_58_21-Virtual machines - Windows Azure

From the client machine, start PowerShell and type

Obviously substituting the IP address of the Azure VM you obtain from the Azure Portal

If you already have trusted hosts, use –Concatenate to avoid overwriting the others.
To be sure,

Should show you the entry you just created.

Now, to connect to the Azure VM and start the PowerShell session:

Substitute in the username you created in the Azure portal when creating the VM (or any user you’ve since set up on the box with the relevant permissions) and you should be presented with a login box to confirm the password.

Once that is done, your PowerShell session should be active.

Happy Scripting!