We are preparing to move. As a result of the move, our phone numbers are changing.
Tried to use some code over at DX21 ADSI Reference - note the code below, to modify the phone numbers in AD using KiX, but does not seem to work.
Here is what I have come up with and have to run this through for each of the OUs that I have listed and I am still missing users that need to be changed.
Anyway, here is the code:
Code:
; ListGroupMembership.kix
BREAK ON
$oxl=Createobject('Excel.application')
;Check to insure that Excel is available
IF 0<>@error ?@error ' Excel Application is not found'
SLEEP 4
RETURN
ENDIF
$rc=$oxl.workbooks.open("H:\Gemini Move\AD Logins.xls")
$row=1 ;Row to start at using column headings, change to 0, if needed
WHILE $oxl.cells($row,1).value<>'' ;need a value each time in column 1
$row=$row+1
IF $oxl.cells($row,1).value='' ;Once it gets to a blank row...
$oxl.quit ;quit Excel
$oxl=0 ;set the object to 0
ELSE
$fname=$oxl.cells($row,2).value
$lname=$oxl.cells($row,3).value
$fullname=$fname+' '+$lname
; -- ?$fullname
;$objRootDSE = GetObject("LDAP://RootDSE")
;$strDomain = $objRootDSE.Get("DefaultNamingContext")
;$objDomain = GetObject("LDAP://"+$strDomain )
;$objRDSE = GetObject("LDAP://rootDSE")
; -- Company
;$target = GetObject("LDAP://OU=COMPANY,OU=Companies,DC=DOMAIN,DC=COMPANY2,DC=com")
; -- Information Technology
;$target = GetObject("LDAP://OU=Information Technology,OU=COMPANY,OU=Companies,DC=DOMAIN,DC=COMPANY2,DC=com")
; -- Beaverton
;$target = GetObject("LDAP://OU=Beaverton,OU=COMPANY,OU=Companies,DC=DOMAIN,DC=COMPANY2,DC=com")
; -- West
;$target = GetObject("LDAP://OU=Mail Enabled,OU=Users,OU=Accounts,OU=RBMG,OU=Companies,DC=DOMAIN,DC=COMPANY2,DC=com")
; -- West 1
$target = GetObject("LDAP://OU=West,OU=San Jose,OU=COMPANY1,OU=Companies,DC=DOMAIN,DC=COMPANY2,DC=com")
; -- ?'Error = '+@error+' - '+@serror
;;$loginscript="logon.bat"
FOR EACH $user IN $target
;;IF $user.telephoneNumber=''
;?$user.name
; -- ?RIGHT($user.name,LEN($user.name)-3)
IF $FullName=RIGHT($user.name,LEN($user.name)-3)
?RIGHT($user.name,LEN($user.name)-3)
;;;?RIGHT($user.name,LEN($user.name)-3)+' '+
?$user.telephonenumber
; -- Code to set the phone number
;$user.Put "telephoneNumber", "(000) 123-"+$oxl.cells($row,4).value
;$user.SetInfo
; -- ?$user.userprincipalname
; -- SLEEP 3
LOGGER('c:\phon.csv',RIGHT($user.name,LEN($user.name)-3)+','+$user.telephonenumber+@CRLF)
;;? 'checking user: '+$user.name
;;?$user.telephoneNumber
;;ENDIF
;$script = $user.loginscript
;? 'Logon script error: @error - @serror'
;? 'assigned login script: '+$script
;If $Script <> $loginscript
;? "Current Script for " +$user.name " is: " +$script+ " Should be: " +$loginscript
; REMOVE SemiColons to actually reset logon batch in lines below
; $user.loginscript=$loginscript
; ? 'Error = '+@ERROR+' - '+@SERROR
; $user.SetInfo
; ? 'Error = '+@ERROR+' - '+@SERROR
; ? "Changed current Script for " +$user.name " to: " +$user.loginscript
EndIf
NEXT
ENDIF
LOOP
;? 'If no user was displayed, then no user was retrieved from the OU'
?'Press a key..'
GET $
FUNCTION LOGGER($logfile,$logdata)
DIM $n
WHILE Open(1,$logfile,5)<>0
IF $n
'.'
ELSE
? 'Please wait'
ENDIF
$n=$n+1
IF $n=6
EXIT(1)
ENDIF
SLEEP 1
LOOP
$n=WriteLine(1, $logdata)
$n=Close(1)
ENDFUNCTION
Thanks,
Kent