#146821 - 2005-08-30 10:35 PM
Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
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
|
|
Top
|
|
|
|
#146822 - 2005-08-30 11:12 PM
Re: Phone Number Changes in AD
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
What exactly isn't working? Is the data you are using for name not formatted correctly and as a result you skip it. Or is it that you try to set the phone number and it does not take?
Beaverton...you work for McAfee/AVERT?
|
|
Top
|
|
|
|
#146823 - 2005-08-30 11:29 PM
Re: Phone Number Changes in AD
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
You could do...
Code:
$user.telephonenumber = "(000) 123-"+$oxl.cells($row,4).value $user.setinfo
The reason it doesn't work in KiX is that for the Put method, you have to put the parameters in parens.
Code:
$user.Put("telephoneNumber", "(000) 123-"+$oxl.cells($row,4).value) $user.SetInfo
|
|
Top
|
|
|
|
#146824 - 2005-08-30 11:44 PM
Re: Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Howard,
I work for a Mortgage Company in Lake Oswego (near to Beaverton).
Kent
|
|
Top
|
|
|
|
#146825 - 2005-08-30 11:46 PM
Re: Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Quote:
You could do... Code:
$user.telephonenumber = "(000) 123-"+$oxl.cells($row,4).value $user.setinfo
The reason it doesn't work in KiX is that for the Put method, you have to put the parameters in parens.
Code:
$user.Put("telephoneNumber", "(000) 123-"+$oxl.cells($row,4).value) $user.SetInfo
I have the code working fine.. The problem is that I have to use several OUs to get the appropriate users from it..
And.. Right now, I am only querying the information to get the code working. Putting and doing the setinfo is not implemented as of yet.
Kent
|
|
Top
|
|
|
|
#146826 - 2005-08-31 12:10 AM
Re: Phone Number Changes in AD
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Sorry, Kent, I missed this...
Quote:
...I am still missing users that need to be changed
...somehow.
|
|
Top
|
|
|
|
#146828 - 2005-08-31 06:12 PM
Re: Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Chris,
I will look into the use of fnLDAPQuery() to get the collection.
To answer your question, it is only a phone number change.
Kent
|
|
Top
|
|
|
|
#146829 - 2005-08-31 07:00 PM
Re: Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Chris,
fnLDAPQuery() seems to do the trick!
However, it seems with some of the employees (very few) there are two and three of them in my log file that I am using for testing.
Here is the code now: Code:
CLS BREAK ON
$logfl='H:\Gemini Move\phon.csv' IF EXIST($logfl) DEL $logfl ENDIF $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 $aattributes = "Name", "AdsPath" $sadspath = "LDAP://"+GetObject("LDAP://rootDSE").get("defaultNamingContext") ;$strFilter = "(&(objectClass=User)(Name=*))" $strfilter = "(&(objectClass=User)(Name="+$fullname+"))" $aresults = fnLDAPQuery($aattributes,$sadspath,$strfilter,"Name") ;@error " | " @serror ;? FOR $r=1 TO UBound($aresults,2) $aresults[$c,$r]; ? $user = GetObject($aResults[$c,$r]) ?RIGHT($user.name,LEN($user.name)-3) ?$user.telephonenumber ; -- Set the new Phone Number ;$user.Put("telephoneNumber", "(000) 123-"+$oxl.cells($row,4).value) ;$user.SetInfo NEXT LOGGER($logfl,RIGHT($user.name,LEN($user.name)-3)+','+$user.telephonenumber+@CRLF) $fullname="" ENDIF LOOP ?"Process is complete.. Press a Key" GET $
Thanks again,
Kent
|
|
Top
|
|
|
|
#146830 - 2005-08-31 07:41 PM
Re: Phone Number Changes in AD
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
You may not be parsing through your results correctly...
Code:
For $row = 0 to UBound($aResults) "Name: " + $aResults[$row,0] ? "ADsPath: " + $aResults[$row,1] ? Next
|
|
Top
|
|
|
|
#146831 - 2005-08-31 08:42 PM
Re: Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Chris,
Thanks for that.. Here is the code as it sits now and works fine..
Code:
CLS BREAK ON
$logfl='H:\Gemini Move\phon.csv' IF EXIST($logfl) DEL $logfl ENDIF $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 $aattributes = "Name", "AdsPath" $sadspath = "LDAP://"+GetObject("LDAP://rootDSE").get("defaultNamingContext") ;$strFilter = "(&(objectClass=User)(Name=*))" $strfilter = "(&(objectClass=User)(Name="+$fullname+"))" $aresults = fnLDAPQuery($aattributes,$sadspath,$strfilter,"Name") ;@error " | " @serror ;?
For $r = 0 to UBound($aResults) ;"Name: " + $aResults[$r,0] ? ;"ADsPath: " + $aResults[$r,1] ? $user = GetObject($aResults[$r,1]) ;?RIGHT($user.name,LEN($user.name)-3) ;?$user.telephonenumber ; -- Set the new Phone Number ;$user.Put("telephoneNumber", "(000) 123-"+$oxl.cells($row,4).value) ;$user.SetInfo LOGGER($logfl,$aResults[$r,0]+','+$user.telephonenumber+@CRLF) Next ENDIF LOOP ?"Process is complete.. Press a Key" GET $
Thanks again,
Kent
|
|
Top
|
|
|
|
#146833 - 2005-09-01 12:23 AM
Re: Phone Number Changes in AD
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Made a couple of changes.. It became easier to look for login id versus full name..
Code:
CLS BREAK ON $logfl='H:\Gemini Move\phon.csv' IF EXIST($logfl) DEL $logfl ENDIF LOGGER($logfl,'Login,Name,Phone'+@CRLF) $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\employee phone exts.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 $login=$oxl.cells($row,1).value ;$fname=$oxl.cells($row,2).value ;$lname=$oxl.cells($row,3).value ;$fullname=$fname+' '+$lname ;?$fullname $aattributes = "Name", "AdsPath" $sadspath = "LDAP://"+GetObject("LDAP://rootDSE").get("defaultNamingContext") ;$strFilter = "(&(objectClass=User)(Name=*))" ;$strfilter = "(&(objectClass=User)(Name="+$fullname+"))" $strFilter = "(&(objectClass=User)(sAMAccountName="+$login+"))" $aresults = fnLDAPQuery($aattributes,$sadspath,$strfilter,"Name") ;@error " | " @serror ;?
For $r = 0 to UBound($aResults) ;"ADsPath: " + $aResults[$r,1] ? $user = GetObject($aResults[$r,1]) ;?RIGHT($user.name,LEN($user.name)-3) ?"Name: " + $aResults[$r,0] ?$user.telephonenumber ?$user.sAMAccountName ; -- Set the new Phone Number ;$user.Put("telephoneNumber", "(000) 123-"+$oxl.cells($row,4).value) ;$user.SetInfo LOGGER($logfl,$user.sAMAccountName+','+$aResults[$r,0]+','+$user.telephonenumber+@CRLF) Next ENDIF LOOP ?"Process is complete.. Press a Key" GET $
Thanks,
Kent
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|