Using Get-MgApplicationCount in Graph PowerShell
The Get-MgApplicationCount cmdlet in Microsoft Graph PowerShell is used to retrieve the total number of applications (service principals) in your Microsoft 365 tenant. This cmdlet is particularly useful for administrators who need to monitor the application landscape, enforce governance, or generate reports.
Cmdlet Syntax
Get-MgApplicationCount [-ConsistencyLevel <String>] [-Filter <String>]
- -ConsistencyLevel: <String>: Specifies the consistency level of the query. For this cmdlet to work, you must pass -ConsistencyLevel Eventual.
- -Filter <String>: OData filter to restrict the number of applications counted based on specific criteria.
Usage Examples
Example 1: Get the Total Count of All Applications
To retrieve the total number of applications in your tenant:
Get-MgApplicationCount -ConsistencyLevel Eventual
Example 2: Get the Count of Applications Based on a Filter I
To get the count of applications that have the words "My" in their display name using StartsWith function:
Get-MgApplicationCount -Filter "startswith(displayName,'My')" -ConsistencyLevel Eventual
Example 3: Get the Count of Applications Based on a Filter II
To get the count of all applications that have the display name 'testing-100':
Get-MgApplicationCount -Filter "displayName eq 'testing-100'" -ConsistencyLevel Eventual
Cmdlet Tips
- Always ensure that the -ConsistencyLevel Eventual parameter is included; otherwise, the cmdlet will not work.
- The -Filter parameter supports OData queries, allowing for complex filtering based on application properties.
Possible Errors & Solutions
Error: The 'ConsistencyLevel' header must be set to 'eventual' for this request. Status: 400 (BadRequest)
Cause: The -ConsistencyLevel Eventual parameter was not provided.
Solution: Add the -ConsistencyLevel Eventual parameter to the cmdlet.
Error: Request_UnsupportedQuery
Cause: The -Filter parameter used a syntax or condition that is not supported.
Solution: Review the OData query syntax and ensure it is supported for the -Filter parameter.
Use Cases
- Application Inventory: Regularly count the number of applications in your tenant to monitor growth and ensure compliance with organizational policies.
- Governance: Use the -Filter parameter to count applications with specific attributes, such as those without a particular tag or those created by a specific user.
- Reporting: Integrate this cmdlet into scripts that generate periodic reports on application counts, providing visibility to stakeholders.
Conclusion
The Get-MgApplicationCount cmdlet is a powerful tool for managing and reporting on applications in Microsoft 365. By leveraging its filtering and search capabilities, administrators can gain insights into their application inventory and enforce governance policies effectively. Remember, the key to using this cmdlet is the -ConsistencyLevel Eventual parameter—without it, your queries won't execute successfully.
This cmdlet's versatility makes it an essential component of any administrator's toolkit, whether for regular monitoring, compliance reporting, or responding to specific queries about the application landscape.
Additional Resources:
Graph PowerShell Get-MgApplicationCount Cmdlet Documentation
Microsoft Graph PowerShell Module Documentation
Microsoft Graph API Documentation
Related Articles:
Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell