Cannot bind parameter 'ObjectId'.

%3CLINGO-SUB%20id%3D%22lingo-sub-260533%22%20slang%3D%22en-US%22%3ECannot%20bind%20parameter%20'ObjectId'.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-260533%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20some%20help%20(I'm%20new%20to%20PowerShell)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%20%24UnqAzureSubAdmin%20%3D%20%22CSP-AZG-%24AzureSubNumber-ADMINISTRATOR%22%3CBR%20%2F%3E%3CBR%20%2F%3EPS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%20echo%20%24UnqAzureSubAdmin%3CBR%20%2F%3ECSP-AZG-00015-ADMINISTRATOR%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%20%24miss_cspazgadmin%20%3D%20Get-AzureRMADGroup%20-SearchString%20%24UnqAzureSubAdmin%20%7C%20Select-Object%20Id%3CBR%20%2F%3E%3CBR%20%2F%3EPS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%20echo%20%24miss_cspazgadmin%3CBR%20%2F%3E%3CBR%20%2F%3EId%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E--%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E8bcd5a16-9c91-49fe-90ad-c658ec973692%3CBR%20%2F%3E%3CBR%20%2F%3EPS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%20New-AzureRmRoleAssignment%20-ObjectId%20%24miss_cspazgadmin%20-RoleDefinitionName%20ADMINISTRATOR%20-Scope%20%22%24subs%22%3CBR%20%2F%3ENew-AzureRmRoleAssignment%20%3A%20Cannot%20bind%20parameter%20'ObjectId'.%20Cannot%20convert%20the%20%22%40%7BId%3D8bcd5a16-9c91-49fe-90ad-c658ec973692%7D%22%20value%20of%20type%3CBR%20%2F%3E%22Selected.Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory.PSADGroup%22%20to%20type%20%22System.Guid%22.%3CBR%20%2F%3EAt%20line%3A1%20char%3A37%3CBR%20%2F%3E%2B%20New-AzureRmRoleAssignment%20-ObjectId%20%24miss_cspazgadmin%20-RoleDefinition%20...%3CBR%20%2F%3E%2B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20InvalidArgument%3A%20(%3A)%20%5BNew-AzureRmRoleAssignment%5D%2C%20ParameterBindingException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20CannotConvertArgumentNoMessage%2CMicrosoft.Azure.Commands.Resources.NewAzureRoleAssignmentCommand%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3EPS%20C%3A%5CWINDOWS%5Csystem32%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EI%20can't%20figure%20out%20how%20to%20capture%20value%20of%20ID%20to%20be%20%24miss_cspazgadmin%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%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-260533%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Active%20Directory%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-262362%22%20slang%3D%22en-US%22%3ERe%3A%20Cannot%20bind%20parameter%20'ObjectId'.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-262362%22%20slang%3D%22en-US%22%3EI%E2%80%99m%20Happy%20to%20hear!%20Take%20care%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-262264%22%20slang%3D%22en-US%22%3ERe%3A%20Cannot%20bind%20parameter%20'ObjectId'.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-262264%22%20slang%3D%22en-US%22%3EThank%20you%20Mattias%2C%20that%20worked.%20Thanks%20again%20for%20you%20help.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-260991%22%20slang%3D%22en-US%22%3ERe%3A%20Cannot%20bind%20parameter%20'ObjectId'.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-260991%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20need%20to%20use%20the%20property%20which%26nbsp%3B%20is%20in%20your%20object.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eexample%3A%3C%2FP%3E%3CP%3E%24Foo.Property%3C%2FP%3E%3CP%3EIn%20your%20case%20it%20will%20be%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%24miss_cspazgadmin.%3C%2FSPAN%3E%3CSPAN%3EId%3C%2FSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Eor%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24(%24miss_cspazgadmin.Id)%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Eor%20you%20can%20do%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24miss_cspazgadmin%20%3D%20Get-AzureRMADGroup%20-SearchString%20%24UnqAzureSubAdmin%20%7C%20%25%7B%24_.Id%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New 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
CSP-AZG-00015-ADMINISTRATOR

 

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

PS C:\WINDOWS\system32> echo $miss_cspazgadmin

Id                                  
--                                  
8bcd5a16-9c91-49fe-90ad-c658ec973692

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
Highlighted

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

 

example:

$Foo.Property

In your case it will be:

$miss_cspazgadmin.Id     

or

$($miss_cspazgadmin.Id)        

 

or you can do:

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

               

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