I’ve been working with powershell for a while now but have recently extended my understanding to beyond the scope of Azure. When remote powershell was released I thought this was a perfect way to try and dynamically build compute clusters in Windows. For one of our projects I’ve recently had to use remote powershell to perform a number of operations from creating an Active Directory on the fly (dcpromo) to getting back info from the remote Virtual Machine.
Powershell is enabled by default when you check the enable remote powershell box in Windows Azure. There are two types of remote powershell HTTP and HTTPS. Both are listeners. By default HTTPS is enabled but you have to enable it with a certificate that you can use.
In order to simplify matters and primarily because Michael Washam has a great blog post on enabling powershell with the HTTPS listener I’ll stick with the HTTP one.
We may have a powershell script like this to create a new VM. Note the use of the -EnableWinRMHttp as by default this is not enabled using powershell.
Also the public endpoint has to be created on port 5985 which will allow access to the VM. As long as we open the endpoint we should be able to use remote powershell. If we forget to use the -EnableWinRMHttp switch then we’ll have to go onto the box and type in the following:
This will enable remote powershell if it hasn’t been enabled yet and add a firewall rule to open up the correct port on the virtual machine. It will then enable the credentials acceptance for a remote powershell session on the server and allow remote origin scripts to be executed. All in all it’s better to use -EnableWinRMHttp. If you try and image the above it won’t survive.
When the service management API is used to create a virtual machine it understands that it needs to create powershell listeners so the XML supports this natively. By default the Azure Powershell CmdLets create an HTTPS listener by filling in these details.
Anyway, to connect to this is fairly simple now. We can now just add the following in Powershell:
Once you have this access turning this virtual machine into a domain controller is a doddle. Simply enter the following powershell CmdLet into your newly added remote powershell session and wait!