BenV
BenV

Reputation: 12452

Add user to Azure AD from another Azure AD via powershell

In the Azure portal I can click Add User and select User in another Windows Azure AD directory to add a user from another directory to the current directory (As long as I have sufficient authorization in both directories).

I'd like to be able to do this via powershell, but it doesn't seem possible since you can only connect to a single directory.

Here's the scenario: [email protected] is a global admin in both tenant1 and tenant2. In the portal, I can see and manage both directories while logged as [email protected].
But in powershell, if I do:

$cred = Get-Credential -UserName [email protected]
Connect-MsolService -Credential $cred

I can only see and manage the tenant1 directory. So I tried this:

$cred = Get-Credential -UserName [email protected]
Connect-MsolService -Credential $cred
$user = Get-MsolUser -UserPrincipalName [email protected]

$cred2 = Get-Credential -UserName [email protected]
Connect-MsolService -Credential $cred2
$user | New-MsolUser

But this failed:

New-MsolUser : Unable to create this user because the user principal name provided is not on a verified domain.
At line:1 char:9
+ $user | New-MsolUser
+         ~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [New-MsolUser], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.PropertyDomainValidationException,Microsoft.Online.Administ 
   ration.Automation.NewUser

I'm guessing this just isn't possible, but maybe someone can point out something I missed?

Upvotes: 1

Views: 1771

Answers (1)

Dan Kershaw - MSFT
Dan Kershaw - MSFT

Reputation: 5838

Unfortunately, as you had guessed, this functionality is not currently available through Azure AD PowerShell. It is something that we'd like to add in the future, but I don't have an exact timeframe for this yet.

UPDATE 4/14/2018: Sorry - was not monitoring this. There is now a way to invite a user from another tenant to the current tenant using Microsoft Graph. Please see https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/invitation. It still doesn't look like there's any Azure AD PowerShell for this.

Upvotes: 4

Related Questions