JSI Tip 10601. How can I update all users telephone number to contain only numeric characters?


Using OnlyNumeric.bat, and AdFind freeware to retrieve all the users and their telephone number, and AdMod freeware to update them, I have scripted FixPhoneNumber.bat to update all users telephone numbers so that they only contains the numbers 0 through 9.

The syntax for using FixPhoneNumber.bat is:

FixPhoneNumber

FixPhoneNumber.bat contains:

@echo off
setlocal
set qry=adfind -nodn -csv -nocsvheader -csvdelim ";" -default -f "&(objectcategory=person)(objectclass=user)" distinguishedName telephoneNumber
for /f "Tokens=1,2 Delims=;" %%a in ('%qry%') do (
  if %%b NEQ "" call :doit %%a %%b
)
endlocal
goto :EOF
:doit
set dn=%1
set phone=%2
call OnlyNumeric %phone% nphone
if not defined nphone goto MT
if %phone% EQU "%nphone%" goto :EOF
call :Quiet>nul 2>&1
goto :EOF
:MT
call :QMT>nul 2>&1
goto :EOF
:QMT
admod -b %dn% "telephoneNumber:-"
goto :EOF
:Quiet
admod -b %dn% "telephoneNumber::%nphone%"



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish