PowerShell for Windows Admins

Nov 28 2012   10:44AM GMT

Clearing all telephone information for an AD account

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I had a question through the blog asking how you could clear the telephone, pager and ipphone information from a user account.

Telephone information in AD appears on the General tab telephone and Other..   And on the telephone tab there is home, mobile, pager, fax and ipphone each of which can have a number of Other phone numbers added

I thought it best to write a function that clears all telephone information.  That way you can pick out the bits you need.

function clear-telephoneInfo {            
param (            
switch ($psCmdlet.ParameterSetName) {            
 "ByDN"  {$distname = $dn }            
 "ByName"  {$distname = "cn=$name,$ou" }            
 default {Write-Host "Error!!! Should not be here" }            
## clear telephone from General tab            
$user = [adsi]"LDAP://$distname"            
$user.TelephoneNumber = ' '            
$user.otherTelephone = ' '            
## clear Telephone tab            
## Home Phone            
$user = [adsi]"LDAP://$distname"            
$user.homePhone = ' '            
$user.otherHomePhone = ' '            
## Pager            
$user = [adsi]"LDAP://$distname"            
$user.pager = ' '            
$user.otherPager = ' '            
## Mobile            
$user = [adsi]"LDAP://$distname"            
$user.mobile = ' '            
$user.otherMobile = ' '            
## Fax            
$user = [adsi]"LDAP://$distname"            
$user.facsimileTelephoneNumber = ' '            
$user.otherFacsimileTelephoneNumber = ' '            
## Fax            
$user = [adsi]"LDAP://$distname"            
$user.ipPhone = ' '            
$user.otherIpPhone = ' '            
## Notes            
$user = [adsi]"LDAP://$distname"            
$user.info = ' '            

I created two parameter sets – one for the distinguished name (ByDN) and one where the name and OU are supplied.

The $distname parameter is set based on the parameter set.

An ADSI call gets the user; the telephoneNumber and othertelephone attributes are set to blank strings and the SetInfo() is called to write the changes back.

This is repeated for the other types of phone number and the Notes field on the telephone tab

I broke it up like this to make it easier to pick and choose what you need.  It would be possible to add more parameters to only pick off a particular type of phone number

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: