– using PowerShell

It is part of my DNA, that no matter how easy things have become, it can always become easier.

In this post, I have stated, that the easiest way to create a NAV 2017 environment on Azure is using But what if you want to create the same environment again and again or you need to create an environment in 5 different languages?

Then there is a lot of typing in names, and passwords and a lot of things that can go wrong.

Can’t we automate that part as well?

Of course we can, and the answer is PowerShell.

In the new Azure PowerShell CmdLets there are a set of CmdLets for handling Azure Resource Manager deployments. The following code will produce demo environments with 5 different country versions of NAV:

$VerbosePreference = "Continue"
$ErrorActionPreference = "stop"
Import-Module -Name "AzureRM.Resources"

# Login to your Azure Subscription

# Select subscription
$mysubscriptionID = "<my subscription id>"
Set-AzureRmContext -SubscriptionID $mysubscriptionID

# ARM template
$templateUri = ""

"W1", "DK", "GB", "NA", "DE" | % {
  # Setup parameter array for ARM template
  $country = $_
  $name = "mynav2017$country"
  $Parameters = New-Object -TypeName Hashtable
  $Parameters.Add("vmName", $name)
  $Parameters.Add("adminPassword", (ConvertTo-SecureString -String "<my password>" -AsPlainText -Force))
  $Parameters.Add("country", $country)
  $Parameters.Add("clickonce", "Yes")
  $Parameters.Add("powerBI", "Yes")
  $Parameters.Add("bingMapsKey", "<my BingMaps key>")
  $Parameters.Add("Office365UserName", "<my Office 365 admin email>")
  $Parameters.Add("Office365Password", (ConvertTo-SecureString -String "<my Office 365 admin password>" -AsPlainText -Force))
  $Parameters.Add("Office365CreatePortal", "Yes")

  # GO!
  $location = "West Europe"
  $resourceGroup = New-AzureRmResourceGroup -Name $name -Location $location
  $resourceGroup | Test-AzureRmResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters
  $resourceGroup | New-AzureRmResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters -Name $name

and the following code will remove all 5 environments again:

"W1", "DK", "GB", "NA", "DE" | % {
  # Setup parameter array for ARM template
  $country = $_
  $name = "mynav2017$country"
  Remove-AzureRmResourceGroup -Name $name -Force

It might not be much faster, but it is a whole lot easier.


Freddy Kristiansen
Technical Evangelist

Comments (3)

  1. Syahransyah says:

    Hi Freddy…Very interesting discussion glad that I came across such informative post.

  2. Džoka Mitrov says:

    Hi Freddy

    There’s a typo in

    $name = “mynav2017$coutry”

    Best Regards

    1. FreddyDK says:

      Will fix that, thanks

Skip to main content