{"id":627,"date":"2016-06-12T02:51:15","date_gmt":"2016-06-12T02:51:15","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?p=627"},"modified":"2016-06-12T02:51:15","modified_gmt":"2016-06-12T02:51:15","slug":"managing-azure-government-subscriptions-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azuregov\/managing-azure-government-subscriptions-with-powershell\/","title":{"rendered":"Managing Azure Government Subscriptions with PowerShell"},"content":{"rendered":"<p>**<strong>Update<\/strong> &#8211; 10-26-2016 &#8211; We have added this content to our Azure Gov Documentation.\u00a0 Check <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/documentation-manage-subscriptions\/\">the documentation<\/a> for the latest content.<\/p>\n<p>**<strong>Update<\/strong> &#8211; 6-24-2016 &#8211; Added command for connecting to Azure Active Directory (AAD) in Azure Gov**<\/p>\n<p>Whether you are using Azure PowerShell to manage a large subscription through script or access features that are not currently available in the Azure Portal you will need to connect to Azure Government instead of Azure Public. \u00a0If you have used PowerShell in Azure Public, it is mostly the same.\u00a0 The differences in Azure Government are:<\/p>\n<ul>\n<li>Connecting your account<\/li>\n<li>Region names<\/li>\n<\/ul>\n<p><em>If you have not used PowerShell yet check out the <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/powershell-install-configure\">Introduction to Azure PowerShell<\/a>.<\/em><\/p>\n<h2>Connecting to Azure Government<\/h2>\n<p>When you start PowerShell you have to tell Azure PowerShell to connect to Azure Government by specifying an environment parameter.\u00a0 The parameter will ensure that PowerShell is connecting to all of the correct endpoints (for more details see \u2018Going Deeper\u2019).\u00a0 The collection of endpoints is determined when you connect log into your account.\u00a0 Different APIs require different versions of the environment switch:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"342\">\n<p style=\"text-align: left\"><strong><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dn708504.aspx\">Service Management<\/a> commands:<\/strong><\/p>\n<\/td>\n<td width=\"594\">\n<pre>Add-AzureAccount -Environment AzureUSGovernment<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"342\">\n<p style=\"text-align: left\"><strong><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt125356.aspx\">Resource Management<\/a> commands:<\/strong><\/p>\n<\/td>\n<td width=\"594\">\n<pre>Add-AzureRmAccount -EnvironmentName AzureUSGovernment<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"342\">\n<p style=\"text-align: left\"><strong><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/jj151815.aspx\">Azure Active Directory<\/a> commands:<\/strong><\/p>\n<\/td>\n<td width=\"594\">\n<pre>Connect-MsolService -AzureEnvironment UsGovernment<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Note:<\/strong> Add-AzureRmAccount uses the <strong>EnvironmentName <\/strong>switch instead of Environment.<\/p>\n<p>You may also use the <strong>Environment<\/strong> switch when connecting to a storage account using <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt603703.aspx\">New-AzureStorageContext<\/a> and specify AzureUSGovernment.<\/p>\n<h2>Determining Region<\/h2>\n<p>Once you are connected there is one additional difference \u2013 The regions used to target a service.\u00a0 Every Azure cloud has different regions.\u00a0 You can see them listed on the <a href=\"https:\/\/azure.microsoft.com\/en-us\/regions\/#services\">service availability<\/a> page. \u00a0\u00a0You normally use the region in the <strong>Location<\/strong> parameter for a command.<\/p>\n<p>There is one catch.\u00a0 The Azure Government regions need to be formatted slightly differently from the way they are listed for the PowerShell commands:<\/p>\n<ul>\n<li>US Gov Virginia = USGov Virginia<\/li>\n<li>US Gov Iowa = USGov Iowa<\/li>\n<\/ul>\n<p><em>Note that there is no space between US and Gov when using the <strong>Location<\/strong> Parameter.<\/em><\/p>\n<p>If you ever want to validate the available regions in Azure Government you can run the following commands and it will print the current list:<\/p>\n<blockquote>\n<pre>Get-AzureLocation<\/pre>\n<\/blockquote>\n<p>If you are curious about the available environments across Azure, you can run:<\/p>\n<blockquote>\n<pre>Get-AzureEnvironment<\/pre>\n<\/blockquote>\n<h2>References<\/h2>\n<p>If you are looking for more information you can check out the following:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/Azure\/azure-powershell\">PowerShell docs on GitHub<\/a><\/li>\n<li><a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/2015\/10\/08\/configuring-arm-on-azure-gc\/\">Step-by-step instruction on connecting to Resource Management<\/a><\/li>\n<li><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt619274.aspx\">Azure PowerShell docs on MSDN<\/a><\/li>\n<\/ul>\n<h2>Going Deeper<\/h2>\n<p>As I was looking into making some changes for new features in Azure Government I dug into how the environment capability works.\u00a0 I found it interesting and thought I would share.<\/p>\n<p>Since we have the Azure PowerShell code on GitHub you can actually check out the settings in the <a href=\"https:\/\/github.com\/Azure\/azure-powershell\/blob\/dev\/src\/Common\/Commands.Common.Authentication\/Models\/AzureEnvironment.Methods.cs\">Azure PowerShell Code<\/a><em>.<\/em>\u00a0 If you read through the code, you will find that there is basically a table of URLs toward the bottom of this file.\u00a0 The switch that you pass in to choose and environment.<\/p>\n<p>You can actually add your own Azure Environments using the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dn790377.aspx\">Set-AzureEnvironment<\/a> command.\u00a0 For those you have been working with Azure Government for a while you will recall that originally you had to use this to manually configure the environment.<\/p>\n<p>Another question that comes up \u2013 Why does Add-AzureRmAccount use <strong>EnvironmentName<\/strong>?\u00a0 I am not sure why they chose this but the command does have an <strong>Environment<\/strong> switch. This takes an Environment variable instead of a string like other commands.\u00a0 If you wanted to use that switch you would need to do the following:<\/p>\n<blockquote>\n<pre>$envARM = Get-AzureRmEnvironment AzureUSGovernment\nAdd-AzureRmAccount -Environment $envARM<\/pre>\n<\/blockquote>\n<p>Final question \u2013 How do I use this if I am using the <a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/2015\/09\/29\/how-to-use-the-azure-cli-with-azure-government\/\">Azure Command Line Interface (CLI)<\/a> instead of PowerShell.\u00a0 It is pretty much the same:<\/p>\n<blockquote><p>azure login &#8211;username &#8220;name@domain.onmicrosoft.com&#8221; &#8211;password &#8220;password&#8221; &#8211;environment &#8220;AzureUSGovernment&#8221;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>**Update &#8211; 10-26-2016 &#8211; We have added this content to our Azure Gov Documentation.\u00a0 Check the documentation for the latest content. **Update &#8211; 6-24-2016 &#8211; Added command for connecting to Azure Active Directory (AAD) in Azure Gov** Whether you are using Azure PowerShell to manage a large subscription through script or access features that are [&hellip;]<\/p>\n","protected":false},"author":1751,"featured_media":20423,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[15,25],"tags":[387,462,539],"class_list":["post-627","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-management","category-portalpreview","tag-management","tag-powershell","tag-subscriptions"],"acf":[],"blog_post_summary":"<p>**Update &#8211; 10-26-2016 &#8211; We have added this content to our Azure Gov Documentation.\u00a0 Check the documentation for the latest content. **Update &#8211; 6-24-2016 &#8211; Added command for connecting to Azure Active Directory (AAD) in Azure Gov** Whether you are using Azure PowerShell to manage a large subscription through script or access features that are [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/users\/1751"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/comments?post=627"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/627\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media\/20423"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media?parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/categories?post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/tags?post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}