Managing Azure VMs using Powershell from your local desktop

To issue Powershell commands from a local (on-premises) workstation, and have them execute on remote Azure virtual machines, requires certificate based authentication in most cases since local machine and Azure VM often don’t belong to the same Active Directory domain. In Azure Microsoft has a large list of VM templates that can be used in the Gallery to provision VMs. These VMs come with few pre-configured features to facilitate secure powershell remoting into the VMs:

  • WinRM is enabled and configured to listen on HTTPS port 5986
  • A certificate is already created to enable authentication from remote on-premises computers.

This PS script takes advantage of these settings and establishes PS session with Azure VM. Once the session is established, you can issue remote PS commands as shown in the examples.


This script is also available as a function. The function facilitate re-using the code to connect to Azure VMs from other scripts.

Here’s an example of using this function in a larger script:


This script which sets up certificate based SQL mirroring on 2 SQL servers in Azure, (explained in this post) provides an example of using this function.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.