Friday, August 2, 2019

Deploy a template using Powershell in Azure Stack

You can use PowerShell to deploy Azure Resource Manager templates to Azure Stack. This article describes how to use PowerShell to deploy a template.

Run AzureRM PowerShell cmdlets

This example uses AzureRM PowerShell cmdlets and a template stored on GitHub. The template creates a Windows Server 2012 R2 Datacenter virtual machine.
 Note
Before you try this example, make sure that you've configured PowerShell for an Azure Stack user.
  1. Browse the AzureStackGitHub repo and find the 101-simple-windows-vm template. Save the template to this location: C:\templates\azuredeploy-101-simple-windows-vm.json.
  2. Open an elevated PowerShell command prompt.
  3. Replace username and password in the following script with your username and password, then run the script:
    PowerShell:
    # Set deployment variables
    $myNum = "001" # Modify this per deployment
    $RGName = "myRG$myNum"
    $myLocation = "local"
    
    # Create resource group for template deployment
    New-AzureRmResourceGroup -Name $RGName -Location $myLocation
    
    # Deploy simple IaaS template
    New-AzureRmResourceGroupDeployment `
        -Name myDeployment$myNum `
        -ResourceGroupName $RGName `
        -TemplateFile c:\templates\azuredeploy-101-simple-windows-vm.json `
        -NewStorageAccountName mystorage$myNum `
        -DnsNameForPublicIP mydns$myNum `
        -AdminUsername <username> `
        -AdminPassword ("<password>" | ConvertTo-SecureString -AsPlainText -Force) `
        -VmName myVM$myNum `
        -WindowsOSVersion 2012-R2-Datacenter
    
     Important
    Every time you run this script, increment the value of the $myNum parameter to prevent overwriting your deployment.
  4. Open the Azure Stack portal, select Browse, and then select Virtual machines to find your new virtual machine (myDeployment001).

No comments:

Post a Comment

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...