Avatar of Sy Fy
Sy FyFlag for United States of America

asked on 

Need to update user properties in AD

Hello,
I am looking to update user properties in AD.  For example,  We need to add  fill in telephone numbers, Job Titel, Department, Company and Manager's name.  We can
put this information in text file and need a way to update the AD user account using
a script.  I am new to Vbs and any help will be appreciated.

Thanks
Active DirectoryOutlookMicrosoft Applications

Avatar of undefined
Last Comment
Sy Fy
Avatar of pwnbasketz
pwnbasketz
Flag of Afghanistan image

have you thought about multi-selecting all of those instead of making a script?  i'm all for scripting, but if it's not something you're going to have to run on a regular basis, I feel like multi-selecting out of ADUC would be quicker.  (when you select multiple users at the same time and then right-click and go to properties, there is a subset of attributes that you can edit - all of the ones you mentioned would be available within that subset)
Avatar of Krzysztof Pytko
Do you have possibility to download and install free Quest PowerShell module for AD ? If so, you can use that to update these attributes.
http://www.quest.com/powershell/activeroles-server.aspx

First, create CSV file with these headers and data

login;tel;job;department;company;manager

save this file with data as c:\users.csv

and use this syntax in Quest PS

Import-CSV c:\users -Delimiter ";" | %{ Get-QADUser $_."login" | Set-QADUser -Company $_."company" -Department $_."department" -PhoneNumber $_."tel" -Title $_."job" -Manager $_."manager" }

Open in new window


Regards,
Krzysztof
Avatar of mlongoh
mlongoh
Flag of United States of America image

Here's a simple example script that will get you started.  It takes two command line options (userID and value) and updates the user's company field with the value.

So, if it were called ADUpdate.vbs, then from a command prompt you would run
cscript ADUpdate.vbs SMITHB "Widgets Inc." and the user SMITHB would have their company field updated with the value Widgets Inc.

wscript.arguments(0) is the first command line option (SMITHB in the example), and wscript.arguments(1) is the second ("Widgets Inc.").  "Widgets Inc." is enclosed in quotes on the command line because it has a space, otherwise only Widgets would be assigned to wscript.arguments(1).

You can use ADSIEDIT to find the names of the other attributes that you want to update and alter the script to update them as well.  You can have vbscript open a text file or create a batch file with FOR and run the script for each user/values.  If you need more help with that let me know.

'On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)
If wscript.Arguments.count < 2 Then wscript.quit
strUser = wscript.Arguments(0)
NewValue = wscript.Arguments(1)


'Convert the UserID to DN in order to find Distinguished Name
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
strNTName = strDomainName & "\" & strUser
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNTName
' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
strUserDN = Replace(strUserDN, "/", "\/")

wscript.echo strUserDN

Set objUser = GetObject ("LDAP://" & strUserDN)

'Update company field
objUser.company = NewValue
objUser.SetInfo

wscript.quit

Open in new window

Avatar of mlongoh
mlongoh
Flag of United States of America image

To further clarify, objuser.title would be the Title, objuser.telephonenumber would be the phone number, objuser.department... and so on.  So you could have up to wscript.arguments(4).

Once you have the basics working and you can update one user at a time from the command line, you can have vbscript read in a whole text file and process all the users in the text file.  

It would look something like this:
Set fMD = objFSO.OpenTextFile(File, 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

For I = 0 to UBound(arrCMDdata)
  arrLineValues = Split(arrCMDdata(I), ",")
  strUser = arrLineValues(0)
  strTitle = arrLineValues(1)
  strCompany = arrLineValues(2)
Next

Open in new window


I just like to take baby steps to get there.

Ask for help as you go along on this and I'll help you.  This is not a tough thing to do.

One challenge will be the manager field... that's a distinguished name so it's looking for the dn of another user object in AD, and unless you have the Manager's UserID (samaccountName) or distinguished name, you'll be putting that data into a different field.

If you do have that data, there's a different approach to updating that field.  You use a objUser.PutEx 1, "manager", manager'sdistinguishedname instead of objUser.manager = X.

If I have time tonight or tomorrow and you have interest, I'll try to write you a more complete script.  Let me know.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Thank you for helping me guys.   I will basically get a dump from our HR guys, in csv format which will be similar to what Krzysztof has.  I may not be allowed to  run any programs from quest site.  

Example,

jdoe,712-452-1236,Admin Assistant,HR,CompanyName,Supervisor

Could you modify the script to load this info from csv file and update the user profile.

Thanks
Avatar of mlongoh
mlongoh
Flag of United States of America image

Yes.  I'll work on it later and hopefully should be able to provide it tomorrow.  It is a holiday weekend so it might not be available until Tuesday.
Avatar of mlongoh
mlongoh
Flag of United States of America image

Save this code in a text file as UserUpdate.vbs and run it like this:
cscript UserUpdate.vbs HRDump.csv

Change HRDump.csv to whatever the actual file name is (so if it's UserData.csv then run cscript UserUpdate.vbs UserData.csv).

I haven't tested this and won't be able to until Tuesday, but you're welcome to test it yourself if you can't wait.  In either case, before you use this in production, test it with a .CSV that only has 1 or 2 or 3 test entries, so you can prove that it works before using it for the full user list.  Also, I can't guarantee that the manager field will update because it's a distinguished name field that's supposed to reference the manager's AD user object.  But we'll cross that bridge when we come to it.  Here's the code:

On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)

If wscript.Arguments.count < 1 Then wscript.quit

Set fMD = objFSO.OpenTextFile(wscript.arguments(0), 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

For I = 0 to UBound(arrCMDdata)
	arrLineValues = Split(arrCMDdata(I), ",")
	strUser = arrLineValues(0)
	wscript.echo "Updating user " & strUser
	strPhone = arrLineValues(1)
	strTitle = arrLineValues(2)
	strDept = arrLineValues(3)
	strCompany = arrLineValues(4)
	strManager = arrLineValues(5)

	'Convert the UserID to DN in order to find Distinguished Name
	Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
	strNTName = strDomainName & "\" & strUser
	Const ADS_NAME_INITTYPE_GC = 3
	Const ADS_NAME_TYPE_NT4 = 3
	Const ADS_NAME_TYPE_1779 = 1
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	' Use the Get method to retrieve the RPC 1779 Distinguished Name.
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strUserDN = Replace(strUserDN, "/", "\/")

	Set objUser = GetObject ("LDAP://" & strUserDN)

	'Update fields
	objUser.phonenumber = strPhone
	objUser.title = strTitle
	objUser.department = strDept
	objUser.company = strCompany
	objUser.objUser.PutEx 1, "manager", strManager
	objUser.SetInfo

	strPhone = ""
	strTitle = ""
	strDept = ""
	strCompany = ""
	strManager = ""
	arrLineValues = ""
Next

wscript.echo "All done!"
wscript.quit

Open in new window

OK, so in this case your best friend are Microsoft DSTools (DSQUERY and DSMOD) which are available by default on each Domain Controller or any machine with RSAT/Administrative Tools installed.

But first, remove a header from CSV file with column names, leave only data as you showed us in your example, then save this query as batch file (with bat or cmd extension) and run in command-line

@echo off
for /f "tokens=1-6 delims=," %%i in (c:\users.csv) do dsquery user -samid %%i | dsmod user -tel %%j -desc %%k -dept %%l -company %%m -mgr %%n -c

Open in new window


and that's all :)

Krzysztof
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Krzysztof,

I get the following error when I run this command.
%%i was unexpected at this time

Thanks
Avatar of mlongoh
mlongoh
Flag of United States of America image

OK, I tested this and everything works.  
Two items to note:
1) Don't have a header line your csv, just the data.
2) The manager value must be the UserID (samAccountName) of the manager or the manager field won't get updated.  The script converts the UserID to the manager's distinguished name (DN), which is what the manager field requires.  So, if you can't get that from the HR dump, then the script might need to be augmented to do a lastname, firstname lookup to find the DN.  Let me know and I'll help.

Code below.  

'On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)

If wscript.Arguments.count < 1 Then wscript.quit

Set fMD = objFSO.OpenTextFile(wscript.arguments(0), 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

For I = 0 to UBound(arrCMDdata)
   If Len(Trim(arrCMDdata(I))) > 0 Then
	arrLineValues = Split(arrCMDdata(I), ",")
	strUser = arrLineValues(0)
	wscript.echo "Updating user " & strUser
	strPhone = arrLineValues(1)
	strTitle = arrLineValues(2)
	strDept = arrLineValues(3)
	strCompany = arrLineValues(4)
	strManager = arrLineValues(5)

	'Convert the UserID to DN in order to find Distinguished Name
	Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
	strNTName = strDomainName & "\" & strUser
	Const ADS_NAME_INITTYPE_GC = 3
	Const ADS_NAME_TYPE_NT4 = 3
	Const ADS_NAME_TYPE_1779 = 1
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	' Use the Get method to retrieve the RPC 1779 Distinguished Name.
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strUserDN = Replace(strUserDN, "/", "\/")

	Set objUser = GetObject ("LDAP://" & strUserDN)

	strNTName = strDomainName & "\" & strManager
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strManagerDN = Replace(strUserDN, "/", "\/")
	Set objManager = GetObject ("LDAP://" & strManagerDN)
	managerDN = objManager.GET("distinguishedName")

	'Update fields
	objUser.telephonenumber = strPhone
	objUser.title = strTitle
	objUser.department = strDept
	objUser.company = strCompany
	objUser.Put "manager", managerDN

	objUser.SetInfo

	strPhone = ""
	strTitle = ""
	strDept = ""
	strCompany = ""
	strManager = ""
	arrLineValues = ""
   End If
Next

wscript.echo "All done!"
wscript.quit

Open in new window

'On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)

If wscript.Arguments.count < 1 Then wscript.quit

Set fMD = objFSO.OpenTextFile(wscript.arguments(0), 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

For I = 0 to UBound(arrCMDdata)
   If Len(Trim(arrCMDdata(I))) > 0 Then
	arrLineValues = Split(arrCMDdata(I), ",")
	strUser = arrLineValues(0)
	wscript.echo "Updating user " & strUser
	strPhone = arrLineValues(1)
	strTitle = arrLineValues(2)
	strDept = arrLineValues(3)
	strCompany = arrLineValues(4)
	strManager = arrLineValues(5)

	'Convert the UserID to DN in order to find Distinguished Name
	Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
	strNTName = strDomainName & "\" & strUser
	Const ADS_NAME_INITTYPE_GC = 3
	Const ADS_NAME_TYPE_NT4 = 3
	Const ADS_NAME_TYPE_1779 = 1
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	' Use the Get method to retrieve the RPC 1779 Distinguished Name.
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strUserDN = Replace(strUserDN, "/", "\/")

	Set objUser = GetObject ("LDAP://" & strUserDN)

	strNTName = strDomainName & "\" & strManager
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strManagerDN = Replace(strUserDN, "/", "\/")
	Set objManager = GetObject ("LDAP://" & strManagerDN)
	managerDN = objManager.GET("distinguishedName")

	'Update fields
	objUser.telephonenumber = strPhone
	objUser.title = strTitle
	objUser.department = strDept
	objUser.company = strCompany
	objUser.Put "manager", managerDN

	objUser.SetInfo

	strPhone = ""
	strTitle = ""
	strDept = ""
	strCompany = ""
	strManager = ""
	arrLineValues = ""
   End If
Next

wscript.echo "All done!"
wscript.quit

Open in new window

Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Hi,

I ran the script and get the following error.

UpdateUser.vbs(27, 2) Microsoft VBScript runtime error:
Name redefined: 'E_ADS_PROPERTY_NOT_FOUND'
Avatar of mlongoh
mlongoh
Flag of United States of America image

Is it possible that you pasted into your script file twice, so that there's actually two copies of what I posted in there?  The error indicates two instances of line 27, but there's only one in what I posted and it tests OK for me.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

This is the code I copied

'On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)

If wscript.Arguments.count < 1 Then wscript.quit

Set fMD = objFSO.OpenTextFile(wscript.arguments(0), 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

For I = 0 to UBound(arrCMDdata)
   If Len(Trim(arrCMDdata(I))) > 0 Then
      arrLineValues = Split(arrCMDdata(I), ",")
      strUser = arrLineValues(0)
      wscript.echo "Updating user " & strUser
      strPhone = arrLineValues(1)
      strTitle = arrLineValues(2)
      strDept = arrLineValues(3)
      strCompany = arrLineValues(4)
      strManager = arrLineValues(5)

      'Convert the UserID to DN in order to find Distinguished Name
      Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
      strNTName = strDomainName & "\" & strUser
      Const ADS_NAME_INITTYPE_GC = 3
      Const ADS_NAME_TYPE_NT4 = 3
      Const ADS_NAME_TYPE_1779 = 1
      Set objTrans = CreateObject("NameTranslate")
      objTrans.Init ADS_NAME_INITTYPE_GC, ""
      objTrans.Set ADS_NAME_TYPE_NT4, strNTName
      ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
      strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
      strUserDN = Replace(strUserDN, "/", "\/")

      Set objUser = GetObject ("LDAP://" & strUserDN)

      strNTName = strDomainName & "\" & strManager
      objTrans.Init ADS_NAME_INITTYPE_GC, ""
      objTrans.Set ADS_NAME_TYPE_NT4, strNTName
      strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
      strManagerDN = Replace(strUserDN, "/", "\/")
      Set objManager = GetObject ("LDAP://" & strManagerDN)
      managerDN = objManager.GET("distinguishedName")

      'Update fields
      objUser.telephonenumber = strPhone
      objUser.title = strTitle
      objUser.department = strDept
      objUser.company = strCompany
      objUser.Put "manager", managerDN

      objUser.SetInfo

      strPhone = ""
      strTitle = ""
      strDept = ""
      strCompany = ""
      strManager = ""
      arrLineValues = ""
   End If
Next

wscript.echo "All done!"
wscript.quit
Avatar of mlongoh
mlongoh
Flag of United States of America image

Remove line 27 - this one:
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

It's not necessary.  Give it a try again, and if you get another error, remove the ' at the beginning of line 1 so that On Error Resume Next is not commented (an apostrophe or single quote is the "remark" indicator for vbscript - anything that follows it is ignored by the script engine).

Let me know how it goes.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Hi,

I tried but still getting errors , Now I get different errors.
UpdateUsers.vbs(33, 2) (null): 0x80005008
Avatar of mlongoh
mlongoh
Flag of United States of America image

What OS are you running this script on, and are you logged in with a userID that has permissions to update records in AD?
Avatar of mlongoh
mlongoh
Flag of United States of America image

Our AD environments are probably a little different.  Try replacing the line
objTrans.Init ADS_NAME_INITTYPE_GC, ""

with

objTrans.Init 1, "YourDomainName"

and replace "YourDomainName" with the name of your domain.  The short Pre-Windows 2000 domain name.

The ADS_NAME_INITTYPE_GC tells this function to find and use a Global Catalog to handle the translation, and the new line has it using the first domain controller it can find.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Windows 7 and yes my account has access to update records in AD.  I used the powershell and was able to update but I can't use powershell in prod so I can't really use it.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

I tried that but same results
Avatar of mlongoh
mlongoh
Flag of United States of America image

Is your Windows 7 machine joined to the domain?
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Yes it is.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

I tried the for loop method posted by Krzysztof , but I get an error "%%i was unexpected at this time"

@echo off
for /f "tokens=1-6 delims=," %%i in (c:\users.csv) do dsquery user -samid %%i | dsmod user -tel %%j -desc %%k -dept %%l -company %%m -mgr %%n -c
Avatar of mlongoh
mlongoh
Flag of United States of America image

Well you got me scratching my head.  Do you see the "Updating user" message right after you run it (before you get the error)?
Avatar of mlongoh
mlongoh
Flag of United States of America image

Doh!! I think I see the problem.  I'm assuming that you're testing with more than one entry in your CSV file.  Let me make a few changes and re-post.

Sorry for the drag... but I'm confident that we'll get this working soon for you.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Yes,  I have two entries.. sorry about that : -)
Avatar of mlongoh
mlongoh
Flag of United States of America image

OK, one more time.
On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)

If wscript.Arguments.count < 1 Then wscript.quit

Set fMD = objFSO.OpenTextFile(wscript.arguments(0), 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1


For I = 0 to UBound(arrCMDdata)
   If Len(Trim(arrCMDdata(I))) > 0 Then
	arrLineValues = Split(arrCMDdata(I), ",")
	strUser = arrLineValues(0)
	wscript.echo "Updating user " & strUser
	strPhone = arrLineValues(1)
	strTitle = arrLineValues(2)
	strDept = arrLineValues(3)
	strCompany = arrLineValues(4)
	strManager = arrLineValues(5)

	'Convert the UserID to DN in order to find Distinguished Name
	strNTName = strDomainName & "\" & strUser
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	' Use the Get method to retrieve the RPC 1779 Distinguished Name.
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strUserDN = Replace(strUserDN, "/", "\/")

	Set objUser = GetObject ("LDAP://" & strUserDN)

	strNTName = strDomainName & "\" & strManager
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strManagerDN = Replace(strUserDN, "/", "\/")
	Set objManager = GetObject ("LDAP://" & strManagerDN)
	managerDN = objManager.GET("distinguishedName")

	'Update fields
	objUser.telephonenumber = strPhone
	objUser.title = strTitle
	objUser.department = strDept
	objUser.company = strCompany
	objUser.Put "manager", managerDN

	objUser.SetInfo

	strPhone = ""
	strTitle = ""
	strDept = ""
	strCompany = ""
	strManager = ""
	arrLineValues = ""
   End If
Next

wscript.echo "All done!"
wscript.quit

Open in new window

Avatar of mlongoh
mlongoh
Flag of United States of America image

No need to apologize... it showed me my mistake.  I was sloppy with my testing - I should have had more than 1 entry in my test csv.  Now I understand why you were getting the errors.

Let me know how it goes with this latest version of the script.

Also, I want to make certain that you understand the limitations of the manager value.
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Sweet !  A for Awsome ! : -)   If I need to update the cell number,  can I just add to this list or it's a complete rewrite.

name,phone,cellphone,fax,Title,department,companyname,supervisor.

jdoe,712-452-1236,712-123-5464,712-125-4567,Admin Assistant,HR,CompanyName,Supervisor
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Could you please update the script to include name,phone,cellphone,fax,Title,department,companyname,supervisor

Thanks,  Really appreciate your help !  and Yes,  I understand the limitation with the Manager value.
ASKER CERTIFIED SOLUTION
Avatar of mlongoh
mlongoh
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Yep,  I did this and it worked.  This is Awosome !  Really appreciate your help with this.
Thanks a bunch.
Avatar of mlongoh
mlongoh
Flag of United States of America image

Is that csv format solid?

name,phone,cellphone,fax,Title,department,companyname,supervisor

It's important to know how each field will be listed in the CSV in order for the script to work.
Avatar of mlongoh
mlongoh
Flag of United States of America image

Per your request:
On Error Resume Next
Dim wsShell, objNetwork, objFSO
Set wsShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strDomainName = uCase(objNetwork.UserDomain)

If wscript.Arguments.count < 1 Then wscript.quit

Set fMD = objFSO.OpenTextFile(wscript.arguments(0), 1)
arrCMDdata = Split(UCase(fMD.Readall),vbcrlf)
fMD.Close

Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1


For I = 0 to UBound(arrCMDdata)
   If Len(Trim(arrCMDdata(I))) > 0 Then
	arrLineValues = Split(arrCMDdata(I), ",")
	strUser = arrLineValues(0)
	wscript.echo "Updating user " & strUser
	strPhone = arrLineValues(1)
	strMobile = arrLineValues(2)
	strFax = arrLineValues(3)
	strTitle = arrLineValues(4)
	strDept = arrLineValues(5)
	strCompany = arrLineValues(6)
	strManager = arrLineValues(7)

	'Convert the UserID to DN in order to find Distinguished Name
	strNTName = strDomainName & "\" & strUser
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	' Use the Get method to retrieve the RPC 1779 Distinguished Name.
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strUserDN = Replace(strUserDN, "/", "\/")

	Set objUser = GetObject ("LDAP://" & strUserDN)

	strNTName = strDomainName & "\" & strManager
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_NT4, strNTName
	strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
	strManagerDN = Replace(strUserDN, "/", "\/")
	Set objManager = GetObject ("LDAP://" & strManagerDN)
	managerDN = objManager.GET("distinguishedName")

	'Update fields
	objUser.telephonenumber = strPhone
	objUser.title = strTitle
	objUser.department = strDept
	objUser.company = strCompany
	objUser.mobile = strMobile
	objUser.facsimileTelephoneNumber = strFax
	objUser.Put "manager", managerDN

	objUser.SetInfo

	strPhone = ""
	strTitle = ""
	strDept = ""
	strCompany = ""
	strManager = ""
	strMobile = ""
	strFax = ""
	arrLineValues = ""
   End If
Next

wscript.echo "All done!"
wscript.quit

Open in new window

Avatar of Sy Fy
Sy Fy
Flag of United States of America image

ASKER

Yes,  HR can dump the data in any format we give them.  Thanks again.
Outlook
Outlook

Microsoft Outlook is a personal information manager from Microsoft, available as a part of the Microsoft Office suite. Although often used mainly as an email application, it also includes a calendar, task manager, contact manager, note-taker, journal, and web browser.

105K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo