SOLVED

Add multiple users to a list of Admin Roles Groups, PowerShell.

%3CLINGO-SUB%20id%3D%22lingo-sub-1505606%22%20slang%3D%22en-US%22%3EAdd%20multiple%20users%20to%20a%20list%20of%20Admin%20Roles%20Groups%2C%20PowerShell.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1505606%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Guys%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHoping%20you%20can%20assist%20here.%20I%20am%20trying%20to%20add%20a%20list%20of%26nbsp%3B%20users%20who%20are%20currently%20members%20of%20a%20Security%20Group%20to%20several%20different%20Administrative%20Role%20Groups.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24Users%20%3D%20Get-Msolgroup%20-All%20%7C%20Where-Object%20%7B%24_.DisplayName%20-eq%20%22Health%20and%20Safety%202%22%7D%3CBR%20%2F%3EGet-MsolGroupMember%20-GroupObjectId%20%24Users.ObjectId%3CBR%20%2F%3E%24Roles%20%3D%20%40(%22Exchange%20Service%20Administrator%22%2C%20%22Sharepoint%20Service%20Administrator%22%2C%20%22Helpdesk%20Administrator%22)%3CBR%20%2F%3Eforeach%20(%24User%20in%20%24Users)%3CBR%20%2F%3E%7B%3CBR%20%2F%3EAdd-MsolRoleMember%20-RoleMemberEmailAddress%20%24Users.ObjectId%20-RoleName%20%24Roles%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20the%20error%3A%26nbsp%3BAdd-MsolRoleMember%20%3A%20Cannot%20convert%20'System.Object%5B%5D'%20to%20the%20type%20'System.String'%20required%20by%20parameter%20'RoleName'.%20Specified%20method%20is%20not%20supported.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20on%20how%20i%20can%20get%20the%20above%20to%20work%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERobert%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1505606%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

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 -All | Where-Object {$_.DisplayName -eq "Health and Safety 2"}
Get-MsolGroupMember -GroupObjectId $Users.ObjectId
$Roles = @("Exchange Service Administrator", "Sharepoint Service Administrator", "Helpdesk Administrator")
foreach ($User in $Users)
{
Add-MsolRoleMember -RoleMemberEmailAddress $Users.ObjectId -RoleName $Roles
}

 

This is the error: Add-MsolRoleMember : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'RoleName'. Specified method is not supported.

 

Any ideas on how i can get the above to work? 

 

Thanks, 

 

Robert 

 

2 Replies
Best Response confirmed by Vasil Michev (MVP)
Solution

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



@Guido van Dijk 

 

Thanks Guido!! That did it!. 

 

Robert