Agent Identities enable developers to build agents at scale, securely, while ensuring they are well governed and only have the least amount of permission required to perform their purpose. In a recent article I guided you on creating Agent Identity Blueprints with PowerShell and in this article I will show you how to use PowerShell to create Agent Identities, based from your Blueprints.
Page Contents
What is an Agent Identity?
An Agent Identity in Microsoft Entra ID is a unique identity account designed specifically for AI agents, enabling them to operate autonomously within your tenant or extended environment. Unlike traditional application identities, which are stable and managed, Agent Identities accommodate the dynamic nature of AI agents that may be created and destroyed often. They provide essential capabilities such as accessing web services, acting autonomously or on behalf of human users and securely authenticating incoming messages. This identity model addresses security challenges associated with AI agents, ensuring appropriate access controls and management at scale.
Connect to Microsoft Graph as your Agent Identity Blueprint
If you haven’t already created your Agent Identity Blueprint, you need to do this first before you can create your Agent Identity. Head to this article “How to Create an Agent Identity Blueprint With Graph PowerShell” and create your Blueprint, then return back here.
By default, when you create your Blueprint, the AgentIdentity.CreateAsManager permission is pre-granted in the app-only context, which gives it the rights to create Agent Identities as itself. As such, you can connect to Microsoft Graph PowerShell, acting as your Agent Identity Blueprint to create your Agent Identity.
To connect to Microsoft Graph, using the Client Secret assigned to your Agent Identity Blueprint, use the below example code and update the value for $Secret, $ApplicationId & $TenantId
$Secret = "# Client Secret Here"
$ApplicationId = "# Blueprint Application Id Here"
$SecuredPassword = $Secret
$TenantId = "# Tenant Id Here"
$SecuredPasswordPassword = ConvertTo-SecureString `
-String $SecuredPassword -AsPlainText -Force
$ClientSecretCredential = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList $ApplicationId, $SecuredPasswordPassword
Connect-MgGraph -TenantId $tenantID -ClientSecretCredential $ClientSecretCredential To verify you have successfully connected to your Agent Identity Blueprint, run the following command and check the output include the required permission.
Get-MgContext | Select -Expand Scopes Connect to Microsoft Graph with a custom app registration
To create a new Agent Identity from an existing Blueprint, you connect to connect to Microsoft Graph PowerShell in the app-only (or “application”) context, this is because the interactive (or “delegated”) permissions are not yet supported. If you have not done this before, my article on How to use Connect-MgGraph with a Client Secret is the perfect place to start. Follow the guidance in that article to register a new application, then continue on from this point.
Once you app registration has been created, you need to grant the AgentIdentity.Create.All app-only permission to your application for authenticating to Microsoft Graph PowerShell with the access to create agents. Start by connecting to Microsoft Graph PowerShell how you normally would using the below command:
Connect-MgGraph -Scopes Application.Read.All, AppRoleAssignment.ReadWrite.All The use the commands below (modifying the AppName value) to grant the AgentIdentity.Create.All permission. This permission is represented below by the value ad25cc1d-84d8-47df-a08e-b34c2e800819.
$AppName = "MyGraphPowerShellApp" # change this value only
$App = (Get-MgServicePrincipal -Filter "DisplayName eq '$App'")
$GraphId = (Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0000-c000-000000000000'").id
$Permission = "ad25cc1d-84d8-47df-a08e-b34c2e800819"
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $App.Id `
-PrincipalId $App.Id -ResourceId $GraphId -AppRoleId $Permission
Once the permission is successfully granted, you can disconnect from your interactive PowerShell sessions and connect in the app-only context. Use the above linked article to create a client secret on your application, then use the below commands to connect to your application in your current session.
$ApplicationId = "the client id of your application"
$SecuredPassword = "the client secret"
$tenantID = "your tenant id"
$SecuredPasswordPassword = ConvertTo-SecureString -String $SecuredPassword -AsPlainText -Force
$ClientSecretCredential = New-Object `
-TypeName System.Management.Automation.PSCredential `
-ArgumentList $ApplicationId, $SecuredPasswordPassword
Connect-MgGraph -TenantId $tenantID -ClientSecretCredential $ClientSecretCredential You can verify you are successfully connected with the necessary permissions using the following command:
Get-MgContext | Select -Expand Scopes Your response should contain “AgentIdentity.Create.All” returned in your PowerShell session.
Create a new Agent Identity
Once you are connected you can create your Agent Identity based on your blueprint using the below code example. Modify the 3 first variables with your own information.
$bluePrintId = "30a3c794-2d76-482e-afa5-9ae5b900d994" # App Id
$sponsorId = "d27e5154-9e45-493c-a170-dc4ba69c28a2" # User Id
$agentIdName = "OcnAgentIdentity02" # Agent Id Name
$uri = "/beta/servicePrincipals/microsoft.graph.agentIdentity"
$body = @{
displayName = $agentIdName
agentIdentityBlueprintId = $bluePrintId
"[email protected]" = @(
"https://graph.microsoft.com/v1.0/users/$sponsorId"
)
}
Invoke-MgGraphRequest -Method Post -Uri $uri -Body $body -OutputType PSObject After creating your Agent Identity, it will be visible in the Entra Admin centre from Entra ID > Agent ID > All agent identities.


Hi Daniel, I am working through these articles and noted that in section “Connect to Microsoft Graph as your Agent Identity Blueprint” there is a requirement to use the Client Secret assigned to the Blueprint, however your steps used to create the Blueprint use a Managed Identity and not a Secret. How can I utilise the approach in the section above when I have configured the Blueprint as per your “How to Create an Agent Identity Blueprint With Graph Powershell” under heading “Configure credentials for your Agent Identity Blueprint” or could you provide the details of how to create a Blueprint that has a Client Secret.
For anyone that wants to test this and not use a Managed ID it may be useful to use the PS commands listed here to basically create “secret based” credentials https://learn.microsoft.com/en-gb/entra/agent-id/identity-platform/create-blueprint?tabs=powershell#configure-credentials-for-the-agent-identity-blueprint