Forum Discussion
Robert Bollinger
Jul 06, 2020Brass Contributor
Add multiple users to a list of Admin Roles Groups, PowerShell.
Hey Guys, Hoping you can assist here. I am trying to add a list of users who are currently members of a Security Group to several different Administrative Role's. $Users = Get-Msolgroup -A...
- Jul 07, 2020
Hi Robert Bollinger
After reading your script I saw a few issues
The first is $users the result you get is not the user, but only the group
Next when you read the documentation regarding the Add-MsolRoleMember there are 2 parameters available for adding a user (RoleMemberEmailAddress and -RoleMemberObjectId)
I changed your script$group = Get-Msolgroup -All | Where-Object {$_.DisplayName -eq "Health and Safety 2"}$users = Get-MsolGroupMember -GroupObjectId $group.ObjectId$Roles = @("Exchange Service Administrator", "Sharepoint Service Administrator", "Helpdesk Administrator")foreach ($role in $roles ){foreach ($user in $users){Add-MsolRoleMember -RoleName $role -RoleMemberObjectId $User.ObjectId}}
Hope this solves your issue
Regards
Guido
GuidovanDijk
Jul 07, 2020MCT
Hi Robert Bollinger
After reading your script I saw a few issues
The first is $users the result you get is not the user, but only the group
Next when you read the documentation regarding the Add-MsolRoleMember there are 2 parameters available for adding a user (RoleMemberEmailAddress and -RoleMemberObjectId)
I changed your script
$group = Get-Msolgroup -All | Where-Object {$_.DisplayName -eq "Health and Safety 2"}
$users = Get-MsolGroupMember -GroupObjectId $group.ObjectId
$Roles = @("Exchange Service Administrator", "Sharepoint Service Administrator", "Helpdesk Administrator")
foreach ($role in $roles )
{
foreach ($user in $users){
Add-MsolRoleMember -RoleName $role -RoleMemberObjectId $User.ObjectId
}
}
Hope this solves your issue
Regards
Guido
- Robert BollingerJul 07, 2020Brass Contributor