Link to home
Create AccountLog in
Avatar of bsharath
bsharathFlag for India

asked on

Script to update users with the company name in ADS.

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
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

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 ***
Avatar of bsharath

ASKER

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.
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

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 . . .
Avatar of Brian Pierce
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 ?
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*
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.
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"
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account