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.<\/p>\n
UserPrincipalName, Secuirty Group, Action<\/p>\n
test1,G1,Add<\/p>\n
Test2,G2,Add … …<\/p>\n
Tes20,G12,Remove<\/p>\n
I used this for single user<\/p>\n
Connect-MsolService<\/p>\n
$groups = Get-MsolGroup -all -grouptype security | where {$_.DisplayName -eq “G1”}<\/p>\n
$users = Get-MsolUser -all | where {$_.UserPrincipalName -like “Test*”}<\/p>\n
$users | Foreach {Add-MsolGroupMember -GroupObjectId $group.objectid -GroupMemberType “user” -GroupMemberObjectId $_.objectid}<\/p>\n
How would you do it for the above scenario for multiple users?<\/p>","upvoteCount":2,"answerCount":4,"datePublished":"2018-05-01T15:18:05.000Z","author":{"@type":"Person","name":"vasudevkartheekakkur","url":"https://community.spiceworks.com/u/vasudevkartheekakkur"},"suggestedAnswer":[{"@type":"Answer","text":"
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.<\/p>\n
UserPrincipalName, Secuirty Group, Action<\/p>\n
test1,G1,Add<\/p>\n
Test2,G2,Add … …<\/p>\n
Tes20,G12,Remove<\/p>\n
I used this for single user<\/p>\n
Connect-MsolService<\/p>\n
$groups = Get-MsolGroup -all -grouptype security | where {$_.DisplayName -eq “G1”}<\/p>\n
$users = Get-MsolUser -all | where {$_.UserPrincipalName -like “Test*”}<\/p>\n
$users | Foreach {Add-MsolGroupMember -GroupObjectId $group.objectid -GroupMemberType “user” -GroupMemberObjectId $_.objectid}<\/p>\n
How would you do it for the above scenario for multiple users?<\/p>","upvoteCount":2,"datePublished":"2018-05-01T15:18:05.000Z","url":"https://community.spiceworks.com/t/group-based-licensing-for-multiple-users/649144/1","author":{"@type":"Person","name":"vasudevkartheekakkur","url":"https://community.spiceworks.com/u/vasudevkartheekakkur"}},{"@type":"Answer","text":"
I will get this moved, it has nothing to do with Spiceworks and would be better in PowerShell group<\/p>","upvoteCount":1,"datePublished":"2018-05-01T15:46:43.000Z","url":"https://community.spiceworks.com/t/group-based-licensing-for-multiple-users/649144/2","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}},{"@type":"Answer","text":"
By the way, what does groups have to do with licensing?<\/p>","upvoteCount":2,"datePublished":"2018-05-01T16:06:16.000Z","url":"https://community.spiceworks.com/t/group-based-licensing-for-multiple-users/649144/3","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}},{"@type":"Answer","text":"
Welcome!<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>