Search code examples
azurepowershellazure-active-directoryazure-powershell

Get the ObjectID from any object I entered based on the display name?


How can I get the ObjectID from the specific Azure object I entered based on the display name?

The input can be Azure AD App, Azure AD group, or any object type.

$objID = ....

I require this to simplify the below script:

New-AzRoleAssignment -ObjectId $objID `
  -RoleDefinitionName "Contributor" `
  -ResourceGroupName "newly-created-resource-group"

based on: https://learn.microsoft.com/en-us/powershell/module/az.resources/new-azroleassignment?view=azps-9.1.0


Solution

  • After reproducing from my end, I could able to get the object ID using Get-AzureADApplication. Below is the PowerShell script that worked for me.

    $objID = Get-AzureADApplication -Filter "DisplayName eq '<YourDisplayName>'"
    $objID.ObjectId
    

    RESULTS:

    enter image description here