Friday, July 19, 2019

How to add office 365 users in Office 365 security groups = Group type "Security"

Script to bulk upload user to use Office 365 Group of type "Security" Not "Office 365".

1) Create a CSV file with colum name  "UserPrincipalName"
Add all the email, which needs Microsoft 365 license .



Set-ExecutionPolicy unrestricted
Install-Module MSOnline
$AzureAdCred = Get-Credential
Connect-MsolService -Credential $AzureAdCred


Import-CSv -Path D:\Assign D365 license user 1.0.CSV | ForEach {

$UPN=$_.UserPrincipalName

$Users=Get-MsolUser -UserPrincipalName $UPN

# Get the Security Group id from Azure Ad 

$Groupid = Get-MsolGroup -ObjectId 1349607e-825a-45d0-b3a2-068de8f6

$Users | ForEach {Add-MsolGroupMember -GroupObjectId $GroupID.ObjectID -GroupMemberObjectId $Users.ObjectID -GroupMemberType User}

}


No comments:

Post a Comment

HTML

Script:

JS