Use PowerShell to Create a Linux VM in Azure

In a couple of my previous blog articles, I’ve demonstrated how to create a storage account in Azure and how to create a reserved virtual IP address in Azure. Both of those items will be used in today’s blog article so I recommend reading through those previous blog articles if you haven’t already done so.

The goal in this blog article is to build a CentOS based OpenLogic 7.0 VM in Azure except using PowerShell instead using the Azure portal website (GUI):


First, the name of the image that Azure uses to build those VM’s will need to be determined. This can be accomplished using the Get-AzureVMImage cmdlet:


The last one in the previous set of results looks like the image that’s used to create the CentOS based OpenLogic 7.0 VM’s on Azure.

Just to be sure, let’s take a look at the details of that particular image:


Yep. That’s the image. You can also see what locations that particular image is available in as shown in the previous results.

You could also return a list of the locations where that image is available in a more readable format by selecting only the location property, splitting on the semicolon, and sorting by name:


Now to create a cloud service in Azure for our new VM:


I’ve used the process shown in this article on Azure to create SSH keys for my Linux VM. I didn’t install CYGWIN as that article suggested. I followed the process here to install and configure OpenSSL and I used Win32 OpenSSL which can be downloaded from here. I also installed Putty which the article on Azure that I previously referenced suggested.

The public key certificate that was created as shown in that previously referenced Azure article needs to be uploaded to the cloud service that was previously created. It also needs to be added to the user’s account on the Linux VM that we’ll be creating:


If you haven’t already associated a storage account with your Azure subscription, that will need to be accomplished prior to creating the VM, otherwise you’ll receive an error message stating that a default storage account hasn’t been configured or to specify a media location for the VM. This storage account must reside in the same data-center as the VM.


Create an Azure VM config using the New-AzureVMConfig cmdlet, pipe that to Add-AzureProvisioningConfig to set some of the additional options, and then pipe that to New-AzureVM to create the actual VM:


Be patient, the previous command will take a couple of minutes to complete.

I’ve opened the Putty SSH client and logged into the new VM that was created in the prevous step. I’ll verify the version of CentOS that it’s running:


If you’re looking for a client to transfer files to/from your new Linux VM, I’d recommend WinSCP. It’s easy to setup and use and it supports using certificates.


1 Comment

  1. ochuko

    Hi, its a nice article but if you could review and simply, it would be better as vital steps are missing.

    a link to creating the ssh key in power shell


Leave a Reply

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

%d bloggers like this: