Categories

Reading the telephone tab

Searching for users with attributes set on the telephone tab is similar to other searches

function get-TelephoneTab {            
[CmdletBinding(SupportsShouldProcess=$true)]             
param (             
[parameter(ParameterSetName="Home")]            
 [switch]$homephone,            
             
[parameter(ParameterSetName="Pager")]            
 [switch]$pager,            
             
[parameter(ParameterSetName="Mobile")]            
 [switch]$mobile,            
             
[parameter(ParameterSetName="Fax")]            
 [switch]$fax,            
             
[parameter(ParameterSetName="IP")]            
 [switch]$ip,            
             
 [ValidateSet("M", "P", "Q", "S")]            
 [string]$type = "S"            
             
)            
switch ($psCmdlet.ParameterSetName) {            
 "Home"   {$primary = "homePhone"            
           $other = "otherHomePhone"             
          }            
 "Pager"  {$primary = "pager"            
           $other = "otherPager"             
          }            
 "Mobile" {$primary = "mobile"            
           $other = "otherMobile"            
          }            
 "Fax"    {$primary = "facsimileTelephoneNumber"            
           $other = "otherFacsimileTelephoneNumber"             
          }            
 "IP"     {$primary = "ipPhone"             
           $other = "otherIpPhone"            
          }            
 default {Write-Host "Error!!! Should not be here" }            
}            
            
$filt = "(|(&(objectclass=user)(objectcategory=user)($primary=*))(&(objectclass=user)(objectcategory=user)($other=*)))"            
            
switch ($type) {            
#Microsoft            
"M"  {              
       Get-ADUser -LdapFilter $filt -Properties *|             
       Format-Table Name, DistinguishedName, $primary, $other            
            
     }            
#AD provider            
"P" {            
      Get-ChildItem -Filter $filt -Path Ad:\"DC=Manticore,DC=org" -Recurse |            
      foreach {             
        $user = [adsi]"LDAP://$($_.DistinguishedName)"            
        $user | select @{N="Name"; E={$_.name}},             
        @{N="DistinguishedName"; E={$_.distinguishedname}},            
         @{N="$primary"; E={$_."$primary"}},            
         @{N="$other"; E={$_."$other"}}            
      } | Format-Table -AutoSize            
             
    }             
#Quest            
"Q" {            
      Get-QADUser -LdapFilter $filt -IncludeAllProperties |            
      Format-Table Name, DN, $primary, $other                   
    }            
#Script            
"S" {            
$root = [ADSI]""            
$search = [adsisearcher]$root            
$search.Filter = $filt            
$search.SizeLimit = 3000            
$search.FindAll() | foreach {            
             
$user = $_.GetDirectoryEntry()            
$user | select @{N="Name"; E={$_.name}},             
 @{N="DistinguishedName"; E={$_.distinguishedname}},            
 @{N="$primary"; E={$_."$primary"}},            
 @{N="$other"; E={$_."$other"}}            
} | Format-Table -AutoSize            
}            
            
default {Write-Host "Error!!! Should not be here" }                 
} ## end of type switch            
            
}  ## end of function


We take the phone options and type of PowerShell command we want to run as parameters. The attribute names are set as variables.



The LDAP filter may look different  as | = OR. It reads as get me all users with $primary set OR with $other set



We then run the type of PowerShell command chosen in the parameter

Leave a Reply