When I login to the new Azure Portal I see a drop-down at the top right that lets me select a "Directory" from a list of 2. When I login to azure using powershell cmdlet "Login-AzureRmAccount" I am connected to the wrong directory. How can I change to the other directory from within Powershell?
Asked
Active
Viewed 3.0k times
4 Answers
14
You need to specify the TenantID parameter when using Select-AzureRMSubscription:
Select-AzureRmSubscription -SubscripitionID <ID of sub> -TenantId <ID of Azure Tenant>
You can actually just specify the tennant to select the directory, without a subscription ID.
Select-AzureRmSubscription -TenantId <ID of Azure Tenant>

Sam Cogan
- 38,736
- 6
- 78
- 114
-
1Thanks Sam. For me, I found it worked only when I also provided subscription id. I was able to determine the azure AD tenant id by clicking the help icon in the top-right of the Azure portal, then clicking "Show Diagnostics". This displayed a Json file which included the Tenant Id. – tr0users May 24 '16 at 10:16
3
You can also use the instructions explained here.
Basically just type:
Get-AzTenant
You will see something like:
Id Name Category Domains
-- ---- -------- -------
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX MyDirectory Home {me.com, example1.com}
YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY WorkDirectory Home {work.net, Adam.com,...}
Then, you choose the directory/tenant you want:
Set-AzContext -TenantId XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

ibda
- 131
- 2
1
Have a look at https://msdn.microsoft.com/en-us/library/mt125356.aspx In short, you can use the Select-AzureRmSubscription cmdlet to switch to the correct subscription.

CtrlDot
- 349
- 1
- 3
1
In azure portal, select ? Help + Support select Show diagnostics. Here you find TenantID. Next step is to login.
$Credential = Get-Credential
Add-AzureRmAccount -Credential $Credential -TenantId <ID of Azure Tenant>

mtr42
- 11
- 2