We help IT Professionals succeed at work.

Script to update users with the company name in ADS.

379 Views
Last Modified: 2010-03-05
Hi,

I have a file which has these details.
Username:Company name
I need a script which can find this user and update these details in the ADS user properties >Organization > Company.

Is there a script which can do this.
Need results file to generate with succuess and failure.
REgards
Sharath
Comment
Watch Question

Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Hi Sharath,

:: * This script require "UserCompany.txt" file on C: drive root from where it will pick user names (CN).
:: * UserCompany.txt file should be in following format
::   <UserName>:<Description>
::   Like:
::          Farhan Kazi:IBM Pakistan
::          Khurram:IBM Oman
:: * Successful run will generate "UCReport.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .bat extension.

:: *** SCRIPT START ***
@Echo Off
SETLOCAL

IF NOT EXIST C:\UserCompany.txt Goto ShowErr
FOR %%R IN (C:\UserCompany.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\UCReport.txt DEL /F /Q C:\UCReport.txt

FOR /F "delims=: tokens=1-2" %%u IN (C:\UserCompany.txt) Do (
      Echo Changing Company Name of: %%u to "%%v"
      Echo Changing Company Name of: %%u to "%%v" >>C:\UCReport.txt
      dsquery user -name "%%u*" | DSMod user -company "%%v" >>C:\UCReport.txt
)

Goto EndScript
:ShowErr
Echo "UserCompany.txt" file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** SCRIPT END ***

Author

Commented:
Shouldd i user the NT login name or full name.Will it update the exact user?

Can i have a failure report also.If the user not found?

I have 2 more similar questions already posted.Can you help me in those.
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Yes it will write an error inside C:\UCReport.txt (if any)

Change following inside the script:
From:
dsquery user -name "%%u*" | DSMod user -company "%%v" >>C:\UCReport.txt
To:
dsquery user -upn "%%u*" | DSMod user -company "%%v" >>C:\UCReport.txt

Author

Commented:
I get this.

Changing Company Name of: sharathr to "india"
dsmod failed:`Target object for this command' is missing.
type dsmod /? for help.Changing Company Name of: Sharath reddy to " India"
dsmod failed:`Target object for this command' is missing.
type dsmod /? for help.Press any key to continue . . .
Brian PiercePhotographer
CERTIFIED EXPERT
Awarded 2007
Top Expert 2008

Commented:
Are you aware that you can select Multiple Accounts in 2003, right click on Properties and then just type the company name in and ir gets entered into all accounts ?
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Can you please post what result do you get after applying following commands

Click Start - Run -> Cmd.exe
DSQuery user -upn sharathr*
And
DSQuery user -samid sharathr*

Author

Commented:
KCTS

You are correct but i need to change 4 types of company names specific to users.

Say some users are contract so need to mention there company name in the box.Thats why i need a script which can update the company name based on the list.

Author

Commented:
I get this


C:\>DSQuery user -upn sharathr*
Nothing
C:\>DSQuery user -samid sharathr*
"CN=Sharath Reddy,OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countries,DC=Deve
lopment,DC=Group,DC=co,DC=uk"
Systems Engineer
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.