@@ -12,18 +12,29 @@ function Get-ApplicationsWithPermissions {
1212 [CmdletBinding ()]
1313 param (
1414 [Parameter (Mandatory = $true )]
15- $Database
15+ $Database ,
16+
17+ [Parameter ()]
18+ [ValidateSet (' Application' , ' ManagedIdentity' , ' Legacy' , ' ServiceIdentity' )]
19+ [string []]$ExcludeServicePrincipalType
1620 )
1721
22+ # Build optional SQL exclusion clause for service principal types
23+ $excludeClause = ' '
24+ if ($ExcludeServicePrincipalType ) {
25+ $quoted = " '" + ($ExcludeServicePrincipalType -join " ', '" ) + " '"
26+ $excludeClause = " `n and sp.servicePrincipalType not in ($quoted )"
27+ }
28+
1829 # Query ServicePrincipal objects with permissions
1930 # Used by tests 21770, 24518, and 21867
2031 $sql = @"
2132select sp.id, sp.appId, sp.displayName, sp.appOwnerOrganizationId, sp.publisherName,
2233spsi.lastSignInActivity.lastSignInDateTime,
23- sp.owners, sp.signInAudience
34+ sp.owners, sp.signInAudience, sp.servicePrincipalType
2435from main.ServicePrincipal sp
2536 left join main.ServicePrincipalSignIn spsi on spsi.appId = sp.appId
26- where sp.id in
37+ where ( sp.id in
2738 (
2839 select sp.id
2940 from main.ServicePrincipal sp
@@ -39,7 +50,7 @@ where sp.id in
3950 from main.ServicePrincipal) spAppRole
4051 on sp.appRoleId = spAppRole.id
4152 where permissionName is not null
42- )
53+ )) $excludeClause
4354order by spsi.lastSignInActivity.lastSignInDateTime
4455"@
4556
0 commit comments