Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export all SharePoint App Principals using the Microsoft Graph PowerShell Module
Import-Module Microsoft.Graph
Connect-MgGraph -Scopes "Application.Read.All"
$legacyServicePrincipals = Get-MgServicePrincipal -Filter { ServicePrincipalType eq 'Legacy' }
# remove any principals that don't have KeyCredentials (Workflow, Napa, etc.)
$legacyServicePrincipals = $legacyServicePrincipals | Where-Object -Property KeyCredentials
$results = @()
foreach( $legacyServicePrincipal in $legacyServicePrincipals )
{
$results += [PSCustomObject] @{
ServicePrincipalId = $legacyServicePrincipal.Id
ClientId = $legacyServicePrincipal.AppId
DisplayName = $legacyServicePrincipal.DisplayName
CreatedDate = $legacyServicePrincipal.AdditionalProperties["createdDateTime"]
RedirectURL = $legacyServicePrincipal.ReplyUrls -join ','
AppDomain = $legacyServicePrincipal.ServicePrincipalNames[-1] -replace "$($legacyServicePrincipal.AppId)/", ""
StartDateTime = $legacyServicePrincipal.KeyCredentials | SELECT -First 1 -ExpandProperty StartDateTime
EndDateTime = $legacyServicePrincipal.KeyCredentials | SELECT -First 1 -ExpandProperty EndDateTime
}
}
$results | Export-Csv -Path "SharePointAppPrincipals.csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment