Jay Dave
Jay Dave

Reputation: 981

How to access the newly created application's ObjectId from AzureAD v2 cmdlet for PowerShell?

Is there a way to get the most recent ObjectId for a newly created application in AzureAD v2 cmdlet for PowerShell?

Upvotes: 0

Views: 853

Answers (1)

Philippe Signoret
Philippe Signoret

Reputation: 14376

The result of the PowerShell cmdlet New-AzureADApplication will be the Application object, including the ObjectId attribute:

PS C:\> New-AzureADApplication -DisplayName "My Special App" -IdentifierUris @("https://localhost/my-special-app")
ObjectId                             AppId                                DisplayName
--------                             -----                                ----------
4a9c0714-adf9-42f4-9189-a69fa2c33861 0f6b4c20-957a-4c96-b477-5562995fd920 My Special App

The best way to use do this in your script is to place the result in a variable:

PS C:\> $app = New-AzureADApplication -DisplayName "My Special App" -IdentifierUris @("https://localhost/my-special-app")
PS C:\> $app.ObjectId
4a9c0714-adf9-42f4-9189-a69fa2c33861

If you're looking for the ObjectId of an Application object which already exists, you would search for it by name:

PS C:\> Get-AzureADApplication -SearchString "My"
ObjectId                             AppId                                DisplayName
--------                             -----                                -----------
4a9c0714-adf9-42f4-9189-a69fa2c33861 0f6b4c20-957a-4c96-b477-5562995fd920 My Special App
4254aa16-b04d-4ce8-9d0b-9b439984499a a4dfe0f4-4406-4906-af67-7201aef85db7 My Other Special App

(Note: The -SearchString parameter does "startswith" searches, not "contains".)

Upvotes: 2

Related Questions