Jump to content

Recommended Posts

Posted

Hi All

 

We need to modify all of the Student Users properties within our AD

 

We need to add the Student Number to the Description Box of each student.

 

For a user name we use, First inital, First 4 letters of their Surname and the student number.

 

example - jblog12345

 

We think it is possible to create a VB or Batch script to check each user, take the number from their user name and add it to the Description Box for each student.

 

But not sure how to do it

 

Any Advice?

 

Thanks

 

Phil

Posted
Are the student numbers the same length?

 

With in reason

 

There are some student numbers that are only 4 numbers long.

 

But my thinking was that all students have 5 letters at the start of the user name.

 

so its either the 4 or 5 numbers that need to be taken.

 

Thanks

 

Phil

Guest TheLibrarian
Posted
What should the description contain? Just the student number?
Posted

Easiest way really I can see is to use David's excellent Bulk AD Users utility that will read your AD tree and open it up in a spreadsheet (Excel only I'm afraid) and then you can use some excel foo in the description field such as =RIGHT(A1,5) to strip jblog12345 to 12345 and then import it back in.

 

Of course, take many back ups and double triple check what you're doing before you commit it back in.

 

http://www.wisesoft.co.uk/userdata/admin/BulkADUsers_Main.png

 

http://www.wisesoft.co.uk/software/bulkadusers/default.aspx

 

 

EDIT: Be very careful with the "force password change at logon" tick box

Guest TheLibrarian
Posted

I have not tested this use it at your own risk!

 

filename:StudentNumber.bat

@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f %%i in ( 'dsquery user "OU=Pupils,DC=[domain],DC=[domain],DC=[domain],DC=[domain]" -samid * -limit 5 ^| dsget user -samid ^| findstr /i /v /c:"dsget"' ) do (
set fullsamid=%%i
set studentnumber=!fullsamid:~5!
dsquery user -samid !fullsamid! | dsmod user -desc !studentnumber!
)

 

The code above will only target the first 5 accounts it finds in (or under) the Pupils OU, change the 5 after the -limit once you are sure it works.

 

You must change the DC=[domain] entries to fit your domain before this will work at all.

 

Please test this with the limit of 5 or less so that if it does completely go off the rails (it shouldn't but just in case) you only have 5 broken accounts.

 

Once more....

 

I have not tested this use it at your own risk!

Posted

THIS HAS NOT BEEN TESTED

 

This VB Script will trawl through all user account in the defined OU and set the Description property to "New Description"

 

You will need modify the code to read the vairable strChange from the output of a csv or text file that you create using Excel to formulate the required values for the description.

 

Simples!

 

Option Explicit
DIM objConnection, objCommand, objRecordSet, objUser 
DIM strChange, strADsPath, strProperty
strProperty = "Description"
strChange ="New Description"

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
";" & _
"(&(objectCategory=person)(objectClass=user));" & _
"ADsPath;subtree"

Set objRecordSet = objCommand.Execute

DO 
strADsPath = objRecordset.Fields("ADsPath")
Set objUser = GetObject(strADsPath)
objUser.Put strProperty, strChange
objUser.SetInfo
objRecordset.MoveNext

Loop Until objRecordset.EOF

Wscript.Echo objRecordSet.RecordCount & _
" User accounts " & strProperty & " changed to " & strChange

objConnection.Close
Wscript.quit 

Guest TheLibrarian
Posted
Is it good or bad that the OP has gone silent? :twitch:
Posted

I am still here

 

lots of things on currently, but have a technician trying this on a test network - nothing is broken.................. yet!!!

 

thanks guys will get these tired

Guest TheLibrarian
Posted
I am still here

 

lots of things on currently, but have a technician trying this on a test network - nothing is broken.................. yet!!!

 

thanks guys will get these tired

I was just hoping that I hadn't caused a major headache for you if you'd tried my script. :)

Posted
I was just hoping that I hadn't caused a major headache for you if you'd tried my script. :)

 

lol

 

no its cool dude

 

we have a 2008 test network that we can be working with.

 

thanks and will keep you posted

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...