The Get-MsolContact
cmdlet in PowerShell retrieves information about contacts from Microsoft Office 365. Contacts can represent the external individuals or entities that your organization communicates with or tracks in Office 365.
These contacts are not full-fledged user accounts but are stored in the Office 365 directory for various purposes.
In this article, we will discuss how to use the Get-MsolContact cmdlet to retrieve the contacts from the Azure Active Directory.
How to Get All Contacts in Office 365
To get a list of all contacts in your Office 365 tenant, use the Get-MsolContact cmdlet in PowerShell.
Get-MsolContact
This command retrieves a contact object or list of contacts.
How to Get a Contact by Object ID in Office 365
To get a contact object by Object ID in your Office 365 tenant, use the following command.
Get-MsolContact -ObjectId 74b30b26-ee5e-478c-8346-641fcf094fb1
In the above PowerShell script, the Get-MsolContact cmdlet uses the –ObjectId
parameter to specify the object ID of a contact and retrieve a contact.
PS C:\> Get-MsolContact -ObjectId 74b30b26-ee5e-478c-8346-641fcf094fb1
EmailAddress DisplayName
------------ -----------
[email protected] Adam Blasco
How to Get Contacts that Match a String
To filter the contact in Office 365 based on the string, use the following command.
Get-MsolContact -SearchString "adam"
In the above PowerShell script, the Get-MsolContact cmdlet uses the -SearchString
parameter to specify the search criteria that a display name or email address of a contact should start with “adam” and retrieve contacts from Office 365.
PS C:\> Get-MsolContact -SearchString "adam"
EmailAddress DisplayName
------------ -----------
[email protected] Adam Blasco
Cool Tip: How to filter users in Office 365 with PowerShell!
Conclusion
I hope the above article on how to use Get-MsolContact cmdlet in PowerShell to retrieve contacts in Office 365 is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.