Provision Users & Groups in O365 with PowerShell
Tutorial on how to Provision Users & Groups in O365 with PowerShell
Provision a Single User in Office 365
Create a new user called UAT3 with default password = P@ssw0rd and O365 E5 License assigned
User will be prompted to change thier password at first login
$DisplayName = "UAT3 TEST"
$FirstName = "UAT3"
$LastName = "TEST"
$UPN = "[email protected]"
$UsageLocation = "MY"
$O365License = Get-MsolAccountSku | ? AccountSkuID -like "*ENTERPRISEPREMIUM" #E5 License
New-MsolUser -DisplayName $DisplayName -FirstName $FirstName -LastName $LastName `
-UserPrincipalName $UPN -UsageLocation $UsageLocation -LicenseAssignment $O365License.AccountSkuID -Password "P@ssw0rd"
Provision Multiple Users from CSV File in Office 365
Prepare a CSV file which contains UserPrincipalName,FirstName,LastName,DisplayName,UsageLocation,AccountSkuId in Excel and save it as CSV (MS-DOS (.csv)** format
Provision users based on the information from imported CSV file
Import-Csv -Path C:\Temp\O365-NewUsers.csv | foreach {
New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName `
-UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -LicenseAssignment $_.AccountSkuId -Password $_.Password} |
Select DisplayName, FirstName, LastName, UserPrincipalName, UsageLocation, Password | Export-Csv -Path C:\Temp\O365-Result.csv -NoTypeInformation
Users’ Password will be exported to C:\temp\O365-Result.csv and prompted to change their password upon first login
PS C:\Users\admin\Desktop> Get-Content C:\Temp\O365-Result.csv
"DisplayName","FirstName","LastName","UserPrincipalName","UsageLocation","Password"
"UAT4 TEST","UAT4","TEST","[email protected]","MY","Hoc11636"
"UAT5 TEST","UAT5","TEST","[email protected]","MY","Gaz98602"
Office 365 Groups vs distribution lists
Refer to Office 365 groups vs distribution lists – an in-depth comparison to have better understanding on O365 Group & Distribution Lists
Create a new Distribution List called Sales and assign UAT1 & UAT2 users as group members
-RequireSenderAuthenticationEnabled $false is required if you want to allow External Users to send email to this Distribution List
New-DistributionGroup -Name "Sales" -Alias "Sales" -Members @("[email protected]","[email protected]") |
Set-DistributionGroup -EmailAddresses [email protected] -RequireSenderAuthenticationEnabled $false
Create a new Office 365 Group called GROUP1 with Exchange Online PowerShell v2
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -Credential $credential
New-UnifiedGroup -Name "GROUP1" -Alias "GROUP1" -DisplayName "GROUP1" -Members @("[email protected]","[email protected]") -RequireSenderAuthenticationEnabled $false
Send-As permission is required for user to send email using the group Email Address
Add-RecipientPermission -Identity "GROUP1" -Trustee "UAT2" -AccessRights SendAs