Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Created April 21, 2021 14:42
Show Gist options
  • Save joerodgers/dce57892a833ca641a985aaed297aa78 to your computer and use it in GitHub Desktop.
Save joerodgers/dce57892a833ca641a985aaed297aa78 to your computer and use it in GitHub Desktop.
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