Thursday, October 22, 2015

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

 

 

#requires -Modules ActiveDirectory

<#

.SYNOPSIS

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

.EXAMPLE

    .\Remove brackets from phones.ps1

.NOTES

   Developed By:

     n: Dave Colvin

     e: dave.colvin_at_experteq.com

     m : +61411265846

#>

Import-Module ActiveDirectory

clear-host

Get-ADUser -Filter {sAMAccountName -like "dave.colv.in*"} -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