Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Last active August 6, 2026 17:34
Show Gist options
  • Select an option

  • Save joerodgers/6cad3cead8fa39651a4720461ea03fe7 to your computer and use it in GitHub Desktop.

Select an option

Save joerodgers/6cad3cead8fa39651a4720461ea03fe7 to your computer and use it in GitHub Desktop.
Uses the agent inventory API to export the metadata about all declarative agents in the tenant to a csv file.
#requires -modules "Microsoft.Graph.Authentication"
# the agent inventory API is gated behind the A365 license, so user identity needs an A365 license assigned.
# Connect-MgGraph -Scopes "CopilotPackages.Read.All" -ClientId $env:O365_CLIENTID
# as of 8/6/26 this works with application permissions, still need the "CopilotPackages.Read.All" scope!!!
Connect-MgGraph -ClientId $env:CDX_CLIENTID -CertificateThumbprint $env:CDX_THUMBPRINT -TenantId $env:CDX_TENANTID
$uri = "v1.0/copilot/admin/catalog/packages"
$declarativeAgents = do
{
$response = Invoke-MgGraphRequest -Method GET -Uri $uri -OutputType PSObject
$uri = $response.'@odata.nextLink'
# filter results to only declarative agents
$agents = $response.value | Where-Object -Property "type" -match "lob|shared" | Where-Object -Property "elementTypes" -Contains "DeclarativeCopilots"
foreach( $agent in $agents )
{
$agentdetails = Invoke-MgGraphRequest -Method GET -Uri "/beta/copilot/admin/catalog/packages/$($agent.id)" -OutputType PSObject
$agentDefinition = $agentdetails.elementDetails | Where-Object -Property elementType -eq "DeclarativeCopilots"
$agentDefinitionObject = $agentDefinition.elements.definition | ConvertFrom-Json
$startPrompts = $agentDefinitionObject.conversation_starters | ForEach-Object { "Title:{0}, Prompt:{1}" -f $_.title, $_.text }
[PSCustomObject]@{
id = $agentdetails.id
displayName = $agentdetails.displayName
type = $agentdetails.type
shortDescription = $agentdetails.shortDescription
isBlocked = $agentdetails.isBlocked
supportedHosts = $agentdetails.supportedHosts -join ", "
lastModifiedDateTime = $agentdetails.lastModifiedDateTime
publisher = $agentdetails.publisher
availableTo = $agentdetails.availableTo
deployedTo = $agentdetails.deployedTo
elementTypes = $agentdetails.elementTypes -join ", "
platform = $agentdetails.platform
appId = $agentdetails.appId
assetId = $agentdetails.assetId
version = $agentdetails.version
manifestVersion = $agentdetails.manifestVersion
ownerId = $agentdetails.ownerId
manifestId = $agentdetails.manifestId
longDescription = $agentdetails.longDescription
createdDateTime = $agentdetails.createdDateTime
allowedUsers = ($agentdetails.allowedUsersAndGroups | Where-Object -Property resourceType -eq "user" | Select-Object -ExpandProperty resourceId) -join ", "
allowedGroups = ($agentdetails.allowedUsersAndGroups | Where-Object -Property resourceType -eq "group" | Select-Object -ExpandProperty resourceId) -join ", "
acquireUsers = ($agentdetails.acquireUsersAndGroups | Where-Object -Property resourceType -eq "user" | Select-Object -ExpandProperty resourceId) -join ", "
acquireGroups = ($agentdetails.acquireUsersAndGroups | Where-Object -Property resourceType -eq "group" | Select-Object -ExpandProperty resourceId) -join ", "
sharedWithGroups = ($agentdetails.sharedWithUsersAndGroups | Where-Object -Property resourceType -eq "user" | Select-Object -ExpandProperty resourceId) -join ", "
sharedWithUsers = ($agentdetails.sharedWithUsersAndGroups | Where-Object -Property resourceType -eq "group" | Select-Object -ExpandProperty resourceId) -join ", "
definitionVersion = $agentDefinitionObject.version
definitionId = $agentDefinitionObject.id
definitionName = $agentDefinitionObject.name
definitionDescription = $agentDefinitionObject.description
definitionInstructions = $agentDefinitionObject.instructions
definitionStarterPrompts = $startPrompts -join ", "
capabilities = ($agentDefinitionObject.capabilities | Select-Object -ExpandProperty Name) -join ", "
}
}
}
while( $uri )
$timestamp = Get-Date -Format FileDateTime
$declarativeAgents | Export-Csv -Path "C:\_temp\declarativeAgentInventory_$timestamp.csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment