Our team has been receiving a large number of questions in the Microsoft Ignite the Tour Experts area regarding the adoption of Azure Active Directory. One question that comes up frequently is:
"How do I automate the ability to add Azure Active Directory users outside of using Azure Portal?"
This post will detail steps in adding Azure Active Directory users via PowerShell via the simplest way possible allowing others to include the following steps into their automation scripts.
Lets get started.
Install-Module ActiveDirectory
Or confirm the module is loaded using the following command:
Get-Module ActiveDirectory
Connect-AzureAD
Confirm the connection is established and you are attached to the desired AzureAD instance using the following command:
Get-AzureADUser
$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$Passw0rdProfile.Password = "IT0psT@lk"
$params = @{NOTE: It is best practice to pass parameters to a cmdlet when you are assigning more than 2 parameters. This makes it easier to see what parameters need to be assigned to the new user. The above are the minimal parameters we need to assign to create the user.
AccountEnabled = $true
DisplayName = "Mike Finnegan"
PasswordProfile = $PasswordProfile
UserPrincipalName = "FwF@Motor.onmicrosoft.com
MailNickName = "Finnegan"
}
New-AzureADUser @params
Get-AzureADUser
There are other ways to add users to Azure Active Directory and MS Learn has a great learning module entitled Create Azure users and groups in Azure Active Directory. Be sure to also share your scripting tips in the comments below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.