none
Get-MsolRoleMember : Cannot convert 'System.Object[]' to the type 'System.Guid' required by parameter 'RoleObjectId'. RRS feed

  • Question

  • Hello PowerShellers,

    I'm trying to produce a list of certain Admins within 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

    Tuesday, June 18, 2019 10:36 AM

Answers

  • You have to do them one at a time:

    Get-MsolRole -RoleName 'Company Administrator' | 
        ForEach-Object{ Get-MsolRoleMember -RoleObjectId $_.ObjectId }


    \_(ツ)_/

    • Marked as answer by djrolfe Tuesday, June 18, 2019 3:14 PM
    Tuesday, June 18, 2019 11:11 AM
    Moderator

All replies

  • The error is very clear.  You cannot use an array where the command requires a GUID.


    \_(ツ)_/

    Tuesday, June 18, 2019 10:54 AM
    Moderator
  • Thank you for your feedback jrv.

    Do you have any suggestions how I may get the results I'm looking for please?

    Kind Regards, Darren

    Tuesday, June 18, 2019 11:07 AM
  • You have to do them one at a time:

    Get-MsolRole -RoleName 'Company Administrator' | 
        ForEach-Object{ Get-MsolRoleMember -RoleObjectId $_.ObjectId }


    \_(ツ)_/

    • Marked as answer by djrolfe Tuesday, June 18, 2019 3:14 PM
    Tuesday, June 18, 2019 11:11 AM
    Moderator
  • Thank you jrv.

    I know that I could pipe each line to export-csv, but is there a way I could get the output to a single csv please?

    Kind Regards, Darren

    Tuesday, June 18, 2019 12:31 PM
  • Just add Export-Csv to the end of the pipeline.


    \_(ツ)_/

    Tuesday, June 18, 2019 12:36 PM
    Moderator
  • Please pardon my ignorance, but do you mean like this:

    Get-MsolRole -RoleName 'Company Administrator' | ForEach-Object{ Get-MsolRoleMember -RoleObjectId $_.ObjectId } |
    Export-Csv "C:\Itergy\Scripts\DR\AdminsList.csv" -NoTypeInformation -Encoding UTF8
    Get-MsolRole -RoleName 'Service Support Administrator' | ForEach-Object{ Get-MsolRoleMember -RoleObjectId $_.ObjectId } |
    Export-Csv "C:\Itergy\Scripts\DR\AdminsList.csv" -NoTypeInformation -Encoding UTF8
    Get-MsolRole -RoleName 'User Account Administrator' | ForEach-Object{ Get-MsolRoleMember -RoleObjectId $_.ObjectId } |
    Export-Csv "C:\Itergy\Scripts\DR\AdminsList.csv" -NoTypeInformation -Encoding UTF8

    Kind Regards, Darren

    Tuesday, June 18, 2019 12:44 PM
  • Always read the complete help very carefully  for any CmdLet you wish to use:

    help export-csv -online


    \_(ツ)_/

    Tuesday, June 18, 2019 12:47 PM
    Moderator
  • Thank you jrv

    The -append would seem to do the trick.

    Kind Regards, Darren

    Tuesday, June 18, 2019 3:15 PM
  • And now you know how to find these things quickly.


    \_(ツ)_/

    Tuesday, June 18, 2019 4:28 PM
    Moderator
  • Thank you jrv :)
    Wednesday, June 19, 2019 10:37 AM