Getting Started with PowerShell for Azure Government

Recently Microsoft announced two new datacenters that are dedicated to U.S. government customers only.  This includes Federal, State, Local, and Tribal governments and their solution providers.  Benefits of this Government Community Cloud are:

  • Physically isolated datacenter and network
  • Data, applications, and hardware reside in the continental United States
  • Provides true geographic redundancy with datacenters located more than 500 miles apart
  • Operated by screen U.S. persons
  • Committed to meeting rigorous compliance requirements and government policies

To learn more about the Microsoft Azure Government cloud check out the latest information on the Microsoft Azure Government website.

Since the Azure Government cloud is physically isolated, there are a few additional steps that must be completed in order to connect with Microsoft Azure PowerShell:

  • add-AzureEnvironment -name “AzureGovernment” -PublishSettingsFileUrl “https://manage.windowsazure.us/publishsettings/index?client=xplat” -serviceendpoint “https://management.core.usgovcloudapi.net” -managementportalurl “http://manage.windowsazure.us” -StorageEndpoint “core.usgovcloudapi.net”
  • Set-AzureEnvironment “AzureGovernment”

Once the PowerShell environment has been setup the next step is to use the Import-AzurePublishSettingsFile cmdlet to import the settings file you saved in the first step.   After the PublishSettings file has been imported you can use the standard Azure PowerShell cmdlets to manage your Microsoft Azure Government subscription.

If you need to revert back to the Microsoft Azure public cloud you can use the command Remove-AzureEnvironment “AzureGovernment” in Microsoft Azure PowerShell.

2 thoughts on “Getting Started with PowerShell for Azure Government”

  1. Mike, do you have a powershell script to create a new VM?
    My traditional powershell script doesn’t work in AzureGovernment subscription.

    1. Below is a demo script I have used. You will want to modify the script for your specific needs, but hopefully it will get you started.


      #################################################################
      # CreateVM.ps1
      #
      # Create VM with specified storage and specified cloud service
      # VM will be added to the specified VNet and subnet
      # VM will be sized D1 and will have an additional 1TB disk
      #
      #################################################################

      #################################################################
      # Connect to subscription
      #################################################################
      Add-AzureAccount -Environment AzureUSGovernment

      #List out Azure Subscriptions
      $AllSubscriptions = Get-AzureSubscription
      Write-Host "*** Azure Subscriptions ***" -ForegroundColor Green
      $AllSubscriptions | ForEach-Object {Write-Host $_.SubscriptionName -foregroundcolor cyan}
      Write-Host ""

      #prompt for subscription to use
      $subscription = Read-Host "Enter subscription name"
      if ($AllSubscriptions.SubscriptionName -contains $subscription)
      {
      Write-Host "Subscription is valid`r`n" -ForegroundColor Yellow
      Select-AzureSubscription $subscription
      }
      else
      {
      Write-Host "Subscription is not valid. Script is terminating" -ForegroundColor Red
      Exit
      }

      #################################################################
      # Set parameters for the VM
      #################################################################
      $azureLocation = "USGov Virginia"
      $serverName = "DemoVM"
      $serverIP = "10.96.9.4"
      $serverStorage = "myvmstorage"
      $serverService = "demovmService"
      $serverVnet="mydemovnet"
      $serverSubnet="frontend"
      $serverAdmin ="demovm"
      $serverPwd="P@ssw0rd1"
      $disksize=1023
      $disklabel="DataDisk"
      $lun=0
      $hcaching="None"
      $vmSize = "Standard_D1"

      #################################################################
      # Get latest Windows Server 2012 R2 server image
      #################################################################
      $family="Windows Server 2012 R2 Datacenter"
      $image=Get-AzureVMImage | where { $_.ImageFamily -eq $family } | sort PublishedDate -Descending | select -ExpandProperty ImageName -First 1

      Write-Host "Creating VM $serverName"

      #Ensure the correct subscription and storage account is selected
      Select-AzureSubscription -SubscriptionName $subscription –Current
      Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $serverStorage

      #Create VM configuration settings
      $vm1 = New-AzureVMConfig -Name $serverName -InstanceSize $vmSize -ImageName $image
      $vm1 | Add-AzureProvisioningConfig -Windows -AdminUsername $serverAdmin -Password $serverPwd
      $vm1 | Set-AzureSubnet -SubnetNames $serverSubnet.Trim()
      $vm1 | Set-AzureStaticVNetIP -IPAddress $serverIP.Trim()
      $vm1 | Add-AzureDataDisk -CreateNew -DiskSizeInGB $disksize -DiskLabel $disklabel -LUN $lun -HostCaching $hcaching

      #Create the VM
      New-AzureVM -ServiceName $serverService -VMs $vm1 -VNetName $serverVnet -Location $azureLocation

Leave a Reply