Jul 06 2020 12:46 PM - edited Jul 07 2020 05:45 AM
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
Jul 07 2020 05:47 AM
SolutionHi @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
Jul 07 2020 07:00 AM
Jul 07 2020 05:47 AM
SolutionHi @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