Get-MsolRoleMember : Cannot convert 'System.Object[]' to the type 'System.Guid'

Hello PowerShellers,
I’m trying to produce a list of certain Admins with O365.
First I run this:
$cred = Get-Credential
Connect-MsolService -credential $cred
Next I run the following:
$role1 = Get-MsolRole -RoleName “Company Administrator”
$role2 = Get-MsolRole -RoleName “Service Support Administrator”
$role3 = Get-MsolRole -RoleName “User Account Administrator”
Lastly this:
Get-MsolRoleMember -RoleObjectId $role1.ObjectId, $role2.ObjectId, $role3.ObjectId
The output I get is:
Get-MsolRoleMember : Cannot convert ‘System.Object[]’ to the type ‘System.Guid’ required by parameter ‘RoleObjectId’. Specified method is not supported.
At line:2 char:34
+ … ember -RoleObjectId $role1.ObjectId, $role2.ObjectId, $role3.ObjectId
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:slight_smile: [Get-MsolRoleMember], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Online.Administration.Automation.GetRoleMember

Any suggestions on how I can resolve this please?

Kind regards, Darren

quick test, it seems get-msolrolemember only wants a single entry for the roleobjectid

Get-MsolRoleMember -RoleObjectId $role1.ObjectId

that will return your memberships as you want.
so run the command 3 times, or build a hash-table of your rolenames, and loop through that using the get-msolrolemember

Hi David,

I can run this in three separate lines.

I’ve just read the about_Hash_Tables help file but am not clear how to build a hash-table of rolenames?

The help file mentioned “key/value” pairs. Can you provide an example of what you mean please?

Kind Regards, Darren

here is an example of how i’d approach this (assuming the list of roles you need to retrieve is static)
[pre]
$rolenames = “Company Administrator”,“Service Support Administrator”,“User Account Administrator”
connect-msolservice
foreach ($role in $rolenames)
{
$roleid = get-msolrole -rolename “$role”
get-msolrolemember -roleobjectid $roleid.objectid
}
[/pre]

Thank you David.

I will do some testing on that.

Kind Regards, Darren