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

Welcome Forums General PowerShell Q&A Get-MsolRoleMember : Cannot convert 'System.Object[]' to the type 'System.Guid'

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #161690

    Participant
    Topics: 11
    Replies: 20
    Points: 132
    Rank: Participant

    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: (:) [Get-MsolRoleMember], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Online.Administration.Automation.GetRoleMember

    Any suggestions on how I can resolve this please?

    Kind regards, Darren

  • #161720

    Participant
    Topics: 23
    Replies: 154
    Points: 368
    Helping Hand
    Rank: Contributor

    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

  • #161748

    Participant
    Topics: 11
    Replies: 20
    Points: 132
    Rank: Participant

    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

  • #161801

    Participant
    Topics: 23
    Replies: 154
    Points: 368
    Helping Hand
    Rank: Contributor

    here is an example of how i'd approach this (assuming the list of roles you need to retrieve is static)

    $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
    }
    
  • #161913

    Participant
    Topics: 11
    Replies: 20
    Points: 132
    Rank: Participant

    Thank you David.

    I will do some testing on that.

    Kind Regards, Darren

The topic ‘Get-MsolRoleMember : Cannot convert 'System.Object[]' to the type 'System.Guid'’ is closed to new replies.