SOLVED

Azure Cloud Shell error with string

%3CLINGO-SUB%20id%3D%22lingo-sub-2478984%22%20slang%3D%22en-US%22%3EAzure%20Cloud%20Shell%20error%20with%20string%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2478984%22%20slang%3D%22en-US%22%3E%3CP%3EI%20get%20this%20error%3A%3C%2FP%3E%3CP%3ECannot%20convert%20'System.Object%5B%5D'%20to%20the%20type%20'System.String'%20required%20by%20parameter%20'ObjectId'.%20Specified%20method%20is%20not%20%7C%20supported.'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrying%20to%20pass%20this%20variable%20to%26nbsp%3BGet-AzureADDirectoryRoleMember%20%2C%20I%20think%20I'm%20missing%20how%20to%20add%20%22%22%20somewhere%20in%26nbsp%3B%22-ObjectId%20%24admins.ObjectId%22%3F%3C%2FP%3E%3CP%3Ecode%3A%3C%2FP%3E%3CP%3E%24admins%20%3D%20Get-AzureADDirectoryRole%20%7C%20where%7B%24_.displayname%20-like%20%22*administrator%22%7D%3CBR%20%2F%3EGet-AzureADDirectoryRoleMember%20-ObjectId%20%24admins.ObjectId%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2478984%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Active%20Directory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eazure%20cloud%20shell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2479410%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Cloud%20Shell%20error%20with%20string%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2479410%22%20slang%3D%22en-US%22%3EWell%20there%20are%20multiple%20built-in%20roles%20that%20match%20your%20query%2C%20so%20the%20%24admins%20variable%20is%20effectively%20an%20array%2C%20meaning%20that%20%24admins.ObjectId%20is%20not%20a%20string%20either.%20This%20will%20work%3A%3CBR%20%2F%3E%3CBR%20%2F%3EGet-AzureADDirectoryRoleMember%20-ObjectId%20%24admins%5B0%5D.ObjectId%3CBR%20%2F%3E%3CBR%20%2F%3Eand%20repeat%20for%20each%20group.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
New Contributor

I get this error:

Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ObjectId'. Specified method is not | supported.'

 

Trying to pass this variable to Get-AzureADDirectoryRoleMember , I think I'm missing how to add "" somewhere in "-ObjectId $admins.ObjectId"?

code:

$admins = Get-AzureADDirectoryRole | where{$_.displayname -like "*administrator"}
Get-AzureADDirectoryRoleMember -ObjectId $admins.ObjectId

 

 

2 Replies
best response confirmed by EdSchreibman (New Contributor)
Solution
Well there are multiple built-in roles that match your query, so the $admins variable is effectively an array, meaning that $admins.ObjectId is not a string either. This will work:

Get-AzureADDirectoryRoleMember -ObjectId $admins[0].ObjectId

and repeat for each group.
Perfect. Thanks