PowerShell Basics: How To Add A New Azure Active Directory User

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

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.

 

  1. Run PowerShell
     
    Run PowerShell Force AzureAD Password Sync 
  2. 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

     

  3. Next lets connect to your instance of Azure:
     
    Connect-AzureAD

     

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

    Get-AzureADUser

     

  5. 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"
  6. 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.

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

    New-AzureADUser @params
  8. 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.

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.