Forum Discussion

Elvir Karic's avatar
Elvir Karic
Copper Contributor
Sep 22, 2018

Cannot bind parameter 'ObjectId'.

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

 

 

 

 

  • Mattias Borg's avatar
    Mattias Borg
    Brass Contributor

    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}

                   

Resources