Display users by departments using a filter

Scenario description

Let’s say you need a list of members who are either in your sales department or in your marketing department.  When using PowerShell to retrieve data from your Office 365 tenant you can include commands to filter this information based on objects within your data. 

Display users by departments using a filter

To begin, you will need to connect to Azure Active Directory.
Import-Module MSOnline
$credential = get-credential
Connect-MsolService -Credential $credential

This command will retrieve the first 100 users who are in either the Sales or Marketing Departments.

Get-MsolUser -maxresults 100 | Where { $_.Department -eq "Sales" -or $_.Department -eq "Marketing" } | select UserPrincipalName,DisplayName,isLicensed,Department

No Comments