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.
PowerShell Command to Add Users in Office 365
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
# 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
0 Comments