Microsoft Teams – Using Get-CsOnlineUser with Filters (Microsoft Teams PowerShell 5.0.0)


The Get-CsOnlineUser PowerShell cmdlet is a powerful tool that enables you to retrieve information about your Teams users, and with the Teams PowerShell Module 5.0.0 it has been updated with new features and performance improvements to make managing your Teams users even easier (see the Release Notes here)

In this blog post, I will explore the latest enhancements to the Get-CsOnlineUser cmdlet, including significant performance improvements and new filtering capabilities that allow you to retrieve information more efficiently. I will also provide examples of how to use the new attributes as filters in your PowerShell scripts to get the information you need about your Teams users.

Performance Improvements
The image is get-csonlineuser from version 4.9.3 (above) and from version 5.0.0 (below). The test was from the same workstation and on the same tenant. The required time goes down from 34 seconds to 8

Use the New Attributes as Filters in your PowerShell Scripts

At the moment two attributes quoted in the documentation are wrong compared to what you get from the tenant

CompanyName should be Company
State should be StateOrProvince

Note: In the examples I have just created a list of users that match the filter.

This command will retrieve all users who are located in the state of Washington, and in any city that contains “Bell” in its name

Get-CsOnlineUser -Filter {Stateorprovince -eq "WA" -and City -like "Bell"} | ft userprincipalname

This command will retrieve all users who have the “PhoneSystem” feature enabled

Get-CsOnlineUser -Filter {FeatureTypes -contains "PhoneSystem"} | ft userprincipalname

This command will retrieve all users who were created between January 1st and March 6th, 2023

Get-CsOnlineUser -Filter {WhenCreated -gt "2023-01-01T00:00:00Z" -and WhenCreated -lt "2023-03-06T23:59:59Z"} | ft userprincipalname

This command will retrieve all users whose SipProxyAddress contains “m365x01033383.onmicrosoft.com”

Get-CsOnlineUser -Filter {SipProxyAddress -like "*m365x01033383.onmicrosoft.com"} | ft userprincipalname

This command will retrieve all users whose CompanyName is “Contoso”

Get-CsOnlineUser -Filter {Company -eq "Contoso"}

This command will retrieve all users whose HostingProvider is set to ” sipfed.online.lync.com”

Get-CsOnlineUser -Filter {HostingProvider -eq "sipfed.online.lync.com"} | ft userprincipalname

This command will retrieve all users whose Alias contains “John”

Get-CsOnlineUser -Filter {Alias -like "*john*"}

This command will retrieve all soft deleted users who were deleted after January 1st, 2023

Get-CsOnlineUser -Filter {SoftDeletionTimestamp -gt "2023-01-01T00:00:00Z"}

This command will retrieve all users whose PreferredDataLocation is set to “EUR”

Get-CsOnlineUser -Filter {PreferredDataLocation -eq "EUR"}

This command will retrieve all users whose LastName is “Vance”.

Get-CsOnlineUser -Filter {LastName -eq "Vance"}