Forum Discussion

karthik akkur's avatar
karthik akkur
Copper Contributor
May 01, 2018

Group based Licenses for Multiple users in Multiple groups

I have a scenario where i need to take input from the CSV file for multiple users who have their UserprincipalName, Security Group and Action (Add or Remove).I need to write a power shell script to add the users automatically after taking the inputs from the CSV file.   

UserPrincipalName, Secuirty Group, Action

test1,G1,Add

Test2,G2,Add .... ....

Tes20,G12,Remove 

 

I used this for single user

 

Connect-MsolService

 

$groups = Get-MsolGroup -all -grouptype security | where {$_.DisplayName -eq "G1"}

 

$users = Get-MsolUser -all | where {$_.UserPrincipalName -like "Test*"}

 

 

$users | Foreach {Add-MsolGroupMember -GroupObjectId $group.objectid -GroupMemberType “user” -GroupMemberObjectId $_.objectid}

 

 

 How would you do it for the above scenario for multiple users?

1 Reply

  • You're dealing with AAD Groups, not Office 365 Groups. There are tons of examples posted on the internet about how to process AD (or AAD) groups. Maybe you can have a look and see what you can find?

Resources