The Get-MsolServicePrincipal cmdlet in PowerShell gets service principals from Microsoft Office 365.
The syntax to retrieve the service principals from Azure Active Directory is given below.
Get-MsolServicePrincipal
[-SearchString <String>]
-ObjectId <Guid>
-ServicePrincipalName <String>
-AppPrincipalId <Guid>
[-All]
[-MaxResults <Int32>]
[-TenantId <Guid>]
[<CommonParameters>]
In this article, we will discuss how to use the Get-MsolServicePrincipal cmdlet in PowerShell to get a service principal or a list of service principals from Azure Active Directory.
How to Get All Service Principals in Azure Active Directory
To get all service principals in Azure Active Directory, use the Get-MsolServicePrincipal cmdlet in PowerShell.
Get-MsolServicePrincipal
This command displays all the existing service principals in the Office 365 tenant.
How to Get a Service Principal by Name
To get a service principal by using a name, use the Get-MsolServicePricipal cmdlet with the -ServicePrincipalName
parameter.
The -ServicePrincipalName
parameter specifies the name of the service principal or service principals to get.
Get-MsolServicePrincipal -ServicePrincipalName "ShellGeekApp/ShellApp.com"
This command gets a service principal that has a service principal name that starts with “ShellGeekApp/ShellApp.com“.
PS C:\> Get-MsolServicePrincipal -ServicePrincipalName "ShellGeekApp/ShellApp.com"
ExtensionData : System.Runtime.Serialization.ExtensionDataObject
AccountEnabled : True
Addresses : {}
AppPrincipalId : b11edafd-3e79-4695-9d2a-c59e78966d35
DisplayName : ShellGeek App
ObjectId : ed85a14d-780e-4bed-aaf0-96c720085082
ServicePrincipalNames : {b11edafd-3e79-4695-9d2a-c59e78966d35, ShellGeekApp/ShellApp.com}
TrustedForDelegation : False
How to Get a Service Principal Name using an App Principal ID
To get a service principal that has a specific application principal ID, use the Get-MsolServicePrincipal cmdlet with the -AppPrincipalId
parameter.
The -AppPrincipalId
parameter specifies the unique application ID of the service principal to get.
Get-MsolServicePrincipal -AppPrincipalId b11edafd-3e79-4695-9d2a-c59e78966d35
This command returns a service principal name that has a specific application principal ID.
PS C:\> Get-MsolServicePrincipal -AppPrincipalId b11edafd-3e79-4695-9d2a-c59e78966d35
ExtensionData : System.Runtime.Serialization.ExtensionDataObject
AccountEnabled : True
Addresses : {}
AppPrincipalId : b11edafd-3e79-4695-9d2a-c59e78966d35
DisplayName : ShellGeek App
ObjectId : ed85a14d-780e-4bed-aaf0-96c720085082
ServicePrincipalNames : {b11edafd-3e79-4695-9d2a-c59e78966d35, ShellGeekApp/ShellApp.com}
TrustedForDelegation : False
Conclusion
I hope the above article on how to use the Get-MsolServicePrincipal cmdlet in PowerShell to get service principal names in Azure Active Directory is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.