Copy telephone field for all users to ipPhone E64 format

by aubrytj at 2012-10-29 23:23:48

Have this task to populate the ipPhone field with the telephone field - all using the E64 format, thou it is working smoothly - their is one character it just will not replace and that is the dot - yes " . " - no matter where it is in the telephone field it thinks it is a number and keeps it as part of the first 10 digits to populate the ipPhone. Any suggestions is appreciated - I’m thinking I should put another replacement option - yet not sure…

# --------------------------------------------------------------
# Request to copy telephone field for all users to ipPhone field
# Using the E64 format - for VOIP - striping the telephone number
# and using only the first 10 digits all in US Format E64
# Anytime a telephone field has been updated the ipPhone will change
#-----------------------------------------------------------------------

Set-ExecutionPolicy remotesigned
Clear-Host
# Add Quest Snapin
Add-PSSnapin Quest.ActiveRoles.ADManagement
& ‘C:\Program Files\Quest Software\Management Shell for AD\qsft.ps1’

# All users in AD
$Users=(get-qaduser)

foreach ($User in $Users) {
$phone=(get-qaduser -identity $User.name |where {$.phonenumber -ne $null}|select phonenumber)
if ($phone -eq $null) {

} else{

$ipPhone = ($User.PhoneNumber -replace ‘\s|(|)|-’,’’).Replace(‘X’,’;ext=’)
$ipPhone = $ipPhone.Substring(0,10)

%{Get-QADUSer $user.LogonName | Set-QADUser -ObjectAttributes @{ipPhone=$ipPhone}} | Format-Table SamAccountName,Displayname, ModificationDate, description, phonenumber


}

}

Thanks in advance for any tips…
by coderaven at 2012-10-30 06:29:16
Sorry for not such a great solution, but you may be right on the easy side of things. I will look into it a little bit more, I am sure there is a much better and easier solution.

$ipPhone = (($User.PhoneNumber -replace ‘\s|(|)|-’,’’).Replace(‘X’,’;ext=’)).Replace(".","")
$ipPhone = $ipPhone.Substring(0,10)
by aubrytj at 2012-10-31 20:38:28
Thanks coderaven - that definitely works…lots of “replace” still works…
by aubrytj at 2012-11-07 22:53:02
Thank you again coderaven…

So I’m running the script and noticed that I did miss something - with our AD having several 1000 objects - code stopped at 1000…lol - so I added the -sizelimit 0 option…now that it placed in the array little over 9800 objects and then updated the necessary field - it took an avg of 2 hrs…so I then looled into “Searchroot” which seemed to improve the array timing - however the overall performance is still 2 + hrs…

Is there a much way to populate the data needed for over 9800 objects?

Server is a virtual GC with lots of disk space/ram needed and it is among its other 4 GC’s handling requests, the task runs @ midnight and so not much of anything else happening that I can tell…

Let me know if anyone have any ideals…of random thoughts on how to improve the performance of the PS script…???

thanks again…

ta
by RichardSiddaway at 2012-11-08 13:15:08
A couple of points come to mind

You start like this

$Users=(get-qaduser)

foreach ($User in $Users) {
$phone=(get-qaduser -identity $User.name |where {$
.phonenumber -ne $null}|select phonenumber)

so you are getting each user twice.

Can you modify your code so its

get-qaduser | foreach { <change phone number>}

that way you reduce the round trips to AD

Also use the property parameter on get-aduser to reduce the amount of data pulled from AD

I can’t test this at the moment but something like this should work

Set-ExecutionPolicy remotesigned
Clear-Host
# Add Quest Snapin
Add-PSSnapin Quest.ActiveRoles.ADManagement
& ‘C:\Program Files\Quest Software\Management Shell for AD\qsft.ps1’

# All users in AD
get-qaduser -Includedproperties phonenumber |
foreach {
if ($.phonenumber){
$ipPhone = (($
.PhoneNumber -replace ‘\s|&#40;|&#41;|-’,’’).Replace(‘X’,’;ext=’)).Replace(".","")
$ipPhone = $ipPhone.Substring(0,10)

$_ | Set-QADUser -ObjectAttributes @{ipPhone=$ipPhone} | Format-Table SamAccountName,Displayname, ModificationDate, description, phonenumber

}
}
by aubrytj at 2012-11-09 14:56:19
Thanks Richard - have briefly tested in test domain - no issues - will go through some scenarios and record performance…
That made perfect sense - one instead of two actions…
by aubrytj at 2012-11-10 16:33:44
Richard - the difference in time was extremed - from the worst case of 2:hrs 20mins or 2hrs avg - to 40min’s - will continue to monitor - yet I would say this is “SOLVED” - very sweet!

Thanks!

ta