Thursday, October 22, 2015

Script to strip out details from phone numbers ( brackets in this example )



#requires -Modules ActiveDirectory



    Removes and brackets () from phone number fields of an Active Directory


    .\Remove brackets from phones.ps1


   Developed By:

     n: Dave Colvin


     m : +61411265846


Import-Module ActiveDirectory


Get-ADUser -Filter {sAMAccountName -like "*"} -SearchBase "OU=Users,DC=int" -searchscope subtree -Properties telephoneNumber, facsimileTelephoneNumber, homePhone, ipPhone, displayName |

foreach {

write-host "updating -> " $_.displayName

if ($_.telephoneNumber) {set-aduser -identity $_ -replace @{telephoneNumber=$_.telephoneNumber -replace '[()]',''}}

if ($_.facsimileTelephoneNumber) {set-aduser -identity $_ -replace @{facsimileTelephoneNumber=$_.facsimileTelephoneNumber -replace '[()]',''}}

if ($_.homePhone) {set-aduser -identity $_ -replace @{homePhone=$_.homePhone -replace '[()]',''}}

#if ($_.ipPhone) {set-aduser -identity $_ -replace @{ipPhone=$_.ipPhone -replace '[()]',''}}


Post a Comment

Blog Archive