Cannot bind parameter 'ObjectId'.

Copper Contributor

I need some help (I'm new to PowerShell):


PS C:\WINDOWS\system32> $UnqAzureSubAdmin = "CSP-AZG-$AzureSubNumber-ADMINISTRATOR"

PS C:\WINDOWS\system32> echo $UnqAzureSubAdmin


PS C:\WINDOWS\system32> $miss_cspazgadmin = Get-AzureRMADGroup -SearchString $UnqAzureSubAdmin | Select-Object Id

PS C:\WINDOWS\system32> echo $miss_cspazgadmin


PS C:\WINDOWS\system32> New-AzureRmRoleAssignment -ObjectId $miss_cspazgadmin -RoleDefinitionName ADMINISTRATOR -Scope "$subs"
New-AzureRmRoleAssignment : Cannot bind parameter 'ObjectId'. Cannot convert the "@{Id=8bcd5a16-9c91-49fe-90ad-c658ec973692}" value of type
"Selected.Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory.PSADGroup" to type "System.Guid".
At line:1 char:37
+ New-AzureRmRoleAssignment -ObjectId $miss_cspazgadmin -RoleDefinition ...
+                                     ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-AzureRmRoleAssignment], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand
PS C:\WINDOWS\system32>


I can't figure out how to capture value of ID to be $miss_cspazgadmin





3 Replies

You need to use the property which  is in your object.




In your case it will be:





or you can do:

$miss_cspazgadmin = Get-AzureRMADGroup -SearchString $UnqAzureSubAdmin | %{$_.Id}


Thank you Mattias, that worked. Thanks again for you help.
I’m Happy to hear! Take care