Creating an Azure VM with NAV 2015 using PowerShell

  • Post category:Azure
  • Post comments:4 Comments
  • Reading time:4 mins read

This post is well overdue, I admit it. I have demonstrated so many times so far how to create an Azure VM instance running Microsoft Dynamics NAV through a PowerShell script running on your PC, and it’s just about time to share this script and the theory behind it with the world.

To start with, this is what the final script looks like:

Param(
[string]$ServiceName,
[string]$AdminAccount,
[string]$AdminPassword,
[string]$AzurePublishSettingsFile
)

Import-AzurePublishSettingsFile $AzurePublishSettingsFile

New-AzureVMConfig -Name $ServiceName -InstanceSize Basic_A3 -ImageName "9a03679de0e64e0e94fb8d7fd3c72ff1__Dynamics-NAV-2015-RTM-201501NB.01-127GB" `
  | Add-AzureProvisioningConfig -Windows -AdminUsername $AdminAccount -Password $AdminPassword `
  | New-AzureVM -Location 'West Europe' -ServiceName $ServiceName

I saved it as Create-AzureVM.ps1, and I can invoke it like this:

.\Create-AzureVM.ps1 -ServiceName "MyTestNAVInstanceXyz" -AdminAccount "VMAdmin" -AdminPassword "Pa$$w0rd1!" -AzurePublish ".\my.publishsettings"

Easy-peasy-lemon-squeezy. Let’s take a look inside this script and see what it actually does.

First, you must make sure you can talk to Azure through PowerShell on your PC. To do this, you must install the Azure PowerShell module, which is available on this page: http://azure.microsoft.com/en-us/downloads/

Once you install it, if you want to learn more about how to use it, you can follow this page: How to install and configure Azure PowerShell.

Now that you have done this, you are able to call any of the many Azure PowerShell cmdlets from your PC and automate Azure administration tasks, including creation of VMs.

Next step is to get the Azure Subscription Publish Settings file. This file contains secure credentials and additional information about your subscription that you can use in your environment. You need to import it into PowerShell every time you want to do something with Azure through PowerShell. To get this file, simply run the Get-AzurePublishSettingsFile cmdlet from PowerShell. This will open this web page: https://manage.windowsazure.com/publishsettings/index?client=powershell and the download will start automatically.

Obviously, this file contains some very sensitive information and allows anybody in possession of this file to automate anything in your Azure subscription, so keep this file safe.

Now that you have your publish settings file, you can import it using Import-AzurePublishSettingsFile, which is precisely what this simple demo script does as the first step.

Then, the script invokes the New-AzureVMConfig cmdlet, which creates a new VM based on parameters you provide. You can find the detailed explanation of parameters it takes on this link: https://msdn.microsoft.com/en-us/library/azure/dn495159.aspx

The service name and administrator account name and password are arbitrary information that you provide when invoking this script. The service name should be unique, and it’s what you’ll refer your VM when accessing it over internet. It’s the first part of the *.cloudapp.net DNS name.

The most cryptic of all parameters I provided in my script is the ImageName parameter. It contains this value: 9a03679de0e64e0e94fb8d7fd3c72ff1__Dynamics-NAV-2015-RTM-201501NB.01-127GB. And this value is the valid identifier for the Microsoft Dynamics NAV 2015 demo image with CU3 installed. How did I get that value? Like this:

Get-AzureVMImage | Where-Object { $_.Label -like "*Dynamics NAV*" } | Sort-Object { $_.PublishedDate }

This cmdlet shows the list of all images that have “Dynamics NAV” in their label, sorted by the publish date (last entry shown is the newest image). At the time of writing of this article, there are two images that match. You simply need to look for the ImageName field and take its value.

And that’s it. Now you can automate creation of your Microsoft Dynamics NAV 2015 virtual machine in Microsoft Azure. Good luck!

Vjeko

Vjeko has been writing code for living since 1995, and he has shared his knowledge and experience in presentations, articles, blogs, and elsewhere since 2002. Hopelessly curious, passionate about technology, avid language learner no matter human or computer.

This Post Has 4 Comments

  1. Peter Tijsma

    Hi Vjeko,

    Perhaps a stupid question, but why not simply use the Microsoft supplied script on the NAV2015 DVD?

    WindowsPowerShellScripts\Cloud\NAVRemoteAdministrationSamples\HowTo-CreateAzureVM.ps1

    .EXAMPLE
    HowTo-CreateAzureVM -ServiceName “MyNewVM” -DomainName “cloudapp.net” -VHDImageName “MyWin2012image” -VMAdminUserName “vmadmin” -VMAdminPassword “P@ssword” -Location “North Europe”

    1. Vjeko

      Hmmm… good question. Should I now make up an excuse? 😉 In all honesty, I wasn’t even aware it was there… Thanks!

Leave a Reply