Group Membership based on UPN/CSV

I feel stupid asking this, but I understand the for updating group membership the default commands utilize group and user id’s:

Add-MsolGroupMember -GroupObjectId “” -GroupMemberType User -GroupMember””

Doing it by names of groups and users is more difficult from my understanding. I am trying to updated group membership based off a CSV with the only header being UserPrincipalName. This is what I have so far and I feel like I am missing something:

Connect-MsolService $grp = Get-MsolGroup -SearchString 'Group Name' Import-Csv C:test.csv | ForEach-Object {Get-ADUser -Filter "UserPrincipalName -eq '$($_.UserPrincipalName)'" | Add-MsolGroupMember -GroupObjectId $grp.ObjectId -GroupMemberType User 

submitted by /u/Dynamiteboy13
[link] [comments]

Leave a Reply