Get-EntraServicePrincipalMembership

Get a service principal membership.

Syntax

Get-EntraServicePrincipalMembership
   -ServicePrincipalId <String>
   [-All]
   [-Top <Int32>]
   [-Property <String[]>]
   [<CommonParameters>]

Description

The Get-EntraServicePrincipalMembership cmdlet gets the memberships of a service principal in Microsoft Entra ID.

Examples

Example 1: Retrieve the memberships of a service principal

Connect-Entra -Scopes 'Application.Read.All'
$ServicePrincipal = Get-EntraServicePrincipal -Filter "DisplayName eq '<service-principal-display-name>'"
Get-EntraServicePrincipalMembership -ServicePrincipalId $ServicePrincipal.ObjectId

Id                                   DeletedDateTime
--                                   ---------------
11112222-aaaa-3333-bbbb-4444cccc5555

This cmdlet retrieves a specified service principal memberships in Microsoft Entra ID. You can use the command Get-EntraServicePrincipal to get service principal ID.

  • -ServicePrincipalId parameter specifies the service principal ID.

Example 2: Retrieve all memberships of a service principal

Connect-Entra -Scopes 'Application.Read.All'
$ServicePrincipal = Get-EntraServicePrincipal -Filter "DisplayName eq '<service-principal-display-name>'"
Get-EntraServicePrincipalMembership -ServicePrincipalId $ServicePrincipal.ObjectId -All

Id                                   DeletedDateTime
--                                   ---------------
11112222-aaaa-3333-bbbb-4444cccc5555
22223333-cccc-4444-dddd-5555eeee6666
33334444-dddd-5555-eeee-6666ffff7777

This command gets all memberships of a specified service principal.

  • -ServicePrincipalId parameter specifies the service principal ID.

Example 3: Retrieve top two memberships of a service principal

Connect-Entra -Scopes 'Application.Read.All'
$ServicePrincipal = Get-EntraServicePrincipal -Filter "DisplayName eq '<service-principal-display-name>'"
Get-EntraServicePrincipalMembership -ServicePrincipalId $ServicePrincipal.ObjectId -Top 2

Id                                   DeletedDateTime
--                                   ---------------
11112222-aaaa-3333-bbbb-4444cccc5555
22223333-cccc-4444-dddd-5555eeee6666

This command gets top two memberships of a specified service principal.

  • -ServicePrincipalId parameter specifies the service principal ID.

Parameters

-All

List all pages.

Type:System.Management.Automation.SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Property

Specifies properties to be returned

Type:System.String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ServicePrincipalId

Specifies the ID of a service principal in Microsoft Entra ID.

Type:System.String
Aliases:ObjectId
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Top

Specifies the maximum number of records to return.

Type:System.Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False