Note: Before proceed, Install and Configure Azure AD PowerShell
Retrieve single user:
Get-MsolUser -ObjectId <Guid>
————-or—————
Get-MsolUser -UserPrincipalName <UserPrincipalName>
Retrieve all users:
Get-MsolUser -All
Example 1
The following command retrieves all users in the company (up to 500 results).
Get-MsolUser
Example 2
The following command retrieves only first 100 users in the company.
Get-MsolUser -MaxResults 100
Example 3
The following command retrieves all the available users in the company.
Get-MsolUser -All
Example 4
The following command retrieves all the deleted users in the company.
Get-MsolUser -All -ReturnDeletedUsers
Example 5
The following command retrieves the user with the UPN [email protected]
Get-MsolUser -UserPrincipalName [email protected]
Example 6
The following command retrieves all the licensed users
Get-MsolUser -All | Where-Object { $_.isLicensed -eq "TRUE" }
Example 7
The following command retrieves and export all the licensed Office 365 users to csv file.
Get-MsolUser | Where-Object { $_.isLicensed -eq "TRUE" } | Select DisplayName,UserPrincipalName,IsLicensed | Export-Csv c:LicensedUsers.csv -NoTypeInformation
Example 8
The following command retrieves all users based on Department filter.
Get-MsolUser -All | Where { $_.Department -like "*Sales*" -or $_.Department -eq "Marketing" } | Select DisplayName,UserPrincipalName,Department,IsLicensed
Example 9
The following command retrieves and export all the users with when they last changed their passwords in Office 365 to csv file.
Get-MsolUser -All | select DisplayName,UserPrincipalName, LastPasswordChangeTimeStamp | Export-CSV C:LastPasswordChange_Report.csv -NoTypeInformation