Mar 01 2018 08:42 AM
I'm trying to bulk load a csv file of users into a security group.
The line below would do what I want to do except that is asking for all users from a specific domain.
$users = get-msoluser | select userprincipalname,objectid | where {$_.userprincipalname -like “*acme.com*”}
Once the users loaded into $users, I would use the below command line to add them to the relevant security group
$users | foreach {add-msolgroupmember -groupobjectid $group.objectid -groupmembertype “user” -GroupMemberObjectId $_.objectid}
However, what should I do if I have a csv file with UserPrincipleName and I wantto get the object id of the users from that very list?
Best
Mar 01 2018 05:05 PM
You can try something like this:
$users | foreach {add-msolgroupmember -groupobjectid $group.objectid -groupmembertype “user” -GroupMemberObjectId (Get-MsolUser -UserPrincipalName $_.UserPrincipalName).objectid}