Header Ads Widget

Responsive Advertisement

Steps to Add Users in Microsoft 365 Using PowerShell


Are you an IT admin? If so, PowerShell commands are probably a key part of your daily work. In this video, you will know about adding single or multiple user into Office 365 account without any technical hassle.

You can also follow this post to add the same.

PowerShell Command to Add Users in Office 365


Run PowerShell as an Administrator and install module

Install-Module -Name Microsoft.Graph

Import Module

Import-Module Microsoft.Graph

Connect to Microsoft Graph with necessary scopes

Connect-MgGraph -Scopes "User.ReadWrite.All", "Organization.Read.All"

Add Single User using PowerShell

To add Single User, copy and run the below command after changing the details and Password (as you want).

New-MgUser -DisplayName "James Parkar" `

-UserPrincipalName "example@domain.com" `

-MailNickName "james" `

-GivenName "James" `

-Surname "Parkar" `

-UsageLocation "IN" `

-PasswordProfile @{ Password = "Password@123"; ForceChangePasswordNextSignIn = $true } `

-AccountEnabled


Add Multiple users using PowerShell

Run the below command to add multiple users in Office 365.

Note: Don't forget to create a CSV file, change Password and Usage Location before executing the command.

# Import the CSV file

$users = Import-Csv -Path "Location of .csv file"

# Loop through each user in the CSV file

foreach ($user in $users) {

    # Create a new user

    $newUser = New-MgUser -UserPrincipalName $user.UserPrincipalName `

     -DisplayName $user.DisplayName `

     -GivenName $user.FirstName `

     -Surname $user.LastName `

     -JobTitle $user.JobTitle `

     -Department $user.Department `

     -AccountEnabled `

     -MailNickname ($user.UserPrincipalName.Split('@')[0]) `

     -PasswordProfile @{

         ForceChangePasswordNextSignIn = $true

         Password = "TempPassword123!"

     } 

    # Set UsageLocation (required for license assignment)

    Update-MgUser -UserId $newUser.Id -UsageLocation "IN"

}

That's it.

Read More: How to connect and access user in PowerShell?

Read More: Import MBOX to Gmail

 

 


Post a Comment

0 Comments