title: PowerShell: How to select one of multiple Active Directories in Azure
body: <p>I have multiple Azure subscriptions with the same tenant, each one of them has their own Active Directory. When switching subscriptions, I still read/write to the AD of my default subscription. How can I access the other directories with PowerShell cmdlets?</p>
  <p>Get-AzSubscription gives me this:</p>
  <pre><code>Name             Id                                   TenantId                             State
  ----             --                                   --------                             -----
  Subscription 01  10000000-0000-0000-0000-000000000001 abc00000-0000-0000-0000-000000000abc Enabled
  Subscription 02  20000000-0000-0000-0000-000000000002 abc00000-0000-0000-0000-000000000abc Enabled
  Subscription 03  30000000-0000-0000-0000-000000000003 abc00000-0000-0000-0000-000000000abc Enabled
  </code></pre>
  <p>Now I can switch between these like this</p>
  <pre><code>#&gt; Set-AzContext -SubscriptionId &quot;20000000-0000-0000-0000-000000000002&quot;
  #&gt; Get-AzContext
  
  Name             Account                 SubscriptionName  Environment  TenantId
  ----             -------                 ----------------  -----------  --------
  Subscription 02  myaccount@mydomain.com  Subscription 02   AzureCloud   abc00000-0000-0000-0000-000000000abc 
  
  #&gt; Set-AzContext -SubscriptionId &quot;30000000-0000-0000-0000-000000000003&quot;
  #&gt; Get-AzContext
  
  Name             Account                 SubscriptionName  Environment  TenantId
  ----             -------                 ----------------  -----------  --------
  Subscription 03  myaccount@mydomain.com  Subscription 03   AzureCloud   abc00000-0000-0000-0000-000000000abc 
  </code></pre>
  <p>When using Get-AzADUser to retrieve information about a user in these subscriptions' Active Directories, it does not work - it always communicates with the AD of Subscription 01. I also tried to run Select-AzContext instead of Set-AzContext with the same result.</p>
  <p>The ADs have completely different IDs, like 0847BCD0-0000-0000-0000-00000039C76F when looking them up in Azure portal. But could not figure out where to use them.</p>
  <p>Could anyone please explain what I am doing wrong?</p>
  <p><strong>Edit:</strong> Just to illustrate this further, when executing Get-AzADUser I get the same result set no matter what subscription I have selected with Set-AzContext. There are no error messages whatsoever but I'd expect to get the users from the AD of the subscription I have selected.</p>