Updated 9/23/2015: Added parameters to the Add-AzureEnvironment command for Azure Resource Manager support in Azure Government.
Back in January I wrote a short blog post that showed how to get started with Azure PowerShell for Government. In that post the steps required the manual retrieval and use of a publishsettings file.
As a follow-up to the original post, I thought I would show how you can connect to an Azure Government subscription using the Add-AzureAccount cmdlet instead of using a publishsettings file.
Just like the original post, you must first setup a new Azure environment definition using the Add-AzureEnvironment cmdlet as shown below.
Add-AzureEnvironment -name “AzureGovernment” -PublishSettingsFileUrl “https://manage.windowsazure.us/publishsettings/index?client=xplat” -ServiceEndpoint “https://management.core.usgovcloudapi.net” -ManagementPortalUrl “https://manage.windowsazure.us” -StorageEndpoint “core.usgovcloudapi.net” -ActiveDirectoryEndpoint “https://login.windows.net/” -ActiveDirectoryServiceEndpointResourceId “https://management.core.usgovcloudapi.net/” -ResourceManagerEndpo
int “https://management.usgovcloudapi.net” -GalleryEndpoint “https://gallery.usgovcloudapi.net”
The next step is to select that environment by using the Set-AzureEnvironment cmdlet:
Finally using the Add-AzureAccount cmdlet with the -Environment parameter we can add our Azure Government subscription to our PowerShell session:
Add-AzureAccount -Environment “AzureGovernment”
You can now utilize the Azure PowerShell scripts with the Azure Government environment.
One last note: Some Azure PowerShell cmdlets have additional optional parameters (such as -Endpoint) that define the URL endpoint used for the command. I believe in all cases it will default to the endpoint for the Azure commercial environment. To use those cmdlets you will need to provide the appropriate Azure Government endpoint. One cmdlet that uses the -Endpoint parameter is New-AzureStorageContext. In this case the -Endpoint parameter would need to be specified as “core.usgovcloudapi.net” for it to work with an Azure Government subscription.