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.

Run PowerShell



Run PowerShell Force AzureAD Password Sync Run the following command to install the Active Directory module:

Install-Module ActiveDirectory

Or confirm the module is loaded using the following command:



Get-Module ActiveDirectory Next lets connect to your instance of Azure:

Connect-AzureAD Confirm the connection is established and you are attached to the desired AzureAD instance using the following command:



Get-AzureADUser With the connection now confirmed, we now need to generate a password profile object and set the properties of that object via the following command:

$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile

$Passw0rdProfile.Password = "IT0psT@lk" Next we'll assign the parameters for the Get-User command:



$params = @{

AccountEnabled = $true

DisplayName = "Mike Finnegan"

PasswordProfile = $PasswordProfile

UserPrincipalName = "FwF@Motor.onmicrosoft.com

MailNickName = "Finnegan"

} 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.



Lets now create the new user including the parameters that were previously assigned:



New-AzureADUser @params Finally we'll confirm the user has been created via the following command:



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.