Useful scripts/commands to find users - Part II

Goal is to find users with the following criteria

1. Not UM enabled user AND
2. TelephoneNumber range between 3000-3999

The LDAP query to be entered under the advanced tab is

(&(objectclass=user)(!msexchumenabledflags=831)

(|(telephonenumber=3**0) (telephonenumber=3**1) (telephonenumber=3**2) (telephonenumber=3**3) (telephonenumber=3**4) (telephonenumber=3**5) (telephonenumber=3**6) (telephonenumber=3**7) (telephonenumber=3**8) (telephonenumber=3**9)

As for the PowerShell, see below script.

=======================================================================================

$array=$null

get-mailbox –resultsize unlimited | foreach {

            if ($_.umenabled –eq $false){

                        $user= Get-User $_

                        if ($user.phone –match “^(3\d{3})$”){

                              [array]$script:array=$script:array+$user

                              }

                        }

                  }

$array | Select-Object -Property name, phone | Export-Csvc:\TEMP\test.csv

=======================================================================================