The Get-MgUserContactCount cmdlet in Microsoft Graph PowerShell allows admins to retrieve the count of contacts for a specific user in Microsoft 365. This cmdlet is especially helpful when you want a quick overview of user contact data, making it ideal for user account analysis, system reporting, or preparing for migrations.
Get-MgUserContactCount -UserId <String> [<CommonParameters>]
Parameters:
Retrieve the total contact count for a user by specifying their UserId (in this case, the user’s primary email).
Get-MgUserContactCount -UserId "john.doe@domain.com"
Using a loop, you can iterate through a list of users to get each user's contact count.
$userIds = @("user1@domain.com", "user2@domain.com")
foreach ($userId in $userIds) {
$contactCount = Get-MgUserContactCount -UserId $userId
Write-Output "$userId has $contactCount contacts."
}
Retrieve contact count for a user and log it in a CSV file for record-keeping.
$userId = "alice.smith@domain.com"
$contactCount = Get-MgUserContactCount -UserId $userId
$logEntry = [PSCustomObject]@{
UserId = $userId
ContactCount = $contactCount
DateChecked = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
}
$logEntry | Export-Csv -Path "UserContactCountLog.csv" -Append -NoTypeInformation
Error | Cause | Solution |
Get-MgUserContactCount : Not Found | This error typically occurs if the specified UserId is incorrect or if the user account does not exist in Microsoft 365. |
Verify that the UserId is accurate by checking the user’s primary email or object ID in the Azure AD portal. Also, ensure that the user account is active.
|
Insufficient Privileges to Complete the Operation | This error can occur if the account executing the cmdlet lacks the necessary permissions. | Ensure that the account used has the Contacts.Read or Contacts.Read.All permissions in the Microsoft Graph API. Contact your Microsoft 365 administrator if permission adjustments are needed. |
Microsoft.Graph.ServiceException | This is a general error from the Microsoft Graph API, often due to network connectivity issues or temporary service disruptions. | Retry the cmdlet after a few minutes. If the error persists, check the Microsoft 365 Service Health page for any outages. |
The Get-MgUserContactCount cmdlet is a powerful tool for Microsoft 365 administrators needing quick access to contact counts for users across the organization. With a range of practical applications in migration planning, security monitoring, and usage analysis, this cmdlet enhances visibility into Microsoft 365 contact management. Remember to handle common errors by double-checking user IDs and permissions, and leverage this cmdlet's output to support informed decision-making.
© m365corner.com. All Rights Reserved.