Jump to content

Recommended Posts

Posted

Hello,

 

I have inherited a system that has two naming conventions for our pupils home directories. The newer one sensibly uses their SIMS admission number (which is also their AD UPN), however the older accounts have a different naming system - that students need to remember, so that their teachers can navigate to it using an NTFS share. Suffice to say this leads to some disgruntled teachers...

 

What I want to do, is rename these older folders to the students admission number, and then update the path to their home directory within their AD account. I have some ideas for the later part, but I don't know how/if I can get a script to use a .CSV to rename these folders en mass - as we have over 1000 accounts to update!

 

Many thanks in anticipation,

John.

Posted

Right, you share out some of the user folders as \\server\username ?

Are all the username shares all located together ? Say in d:\users\students\ ?

As then all you need to do is share out the d:\users\students and give read access to the staff.

 

If you switch to mapping their shares as \\servername\share\username then you can let windows AD create and (I believe) apply the settings itself. It's just then a case of moving all the data.

Posted

An example:

 

profile path for new students: \\server1\001234 (where the number is their sims number, and AD UPN).

 

profile path for most older students: \\server1\smithj1 (which = surname>). However all these older students have a username of e.g. 002345.

 

both naming system reside on the same server share & folder.

 

 

Unsuprisingly year 9/10 students are having problems remembering these old usernames. I would therefore like to change the name of their folders to match the convention used in the younger years.

 

But, most students will have there stuff in these folders, so rather than just deleting & mass re-creating their accounts, I wondered if a script could mass rename them all using a csv. One column = their old foldername, the next column = their new foldername.

 

Cheers,

John.

Posted

Here goes:

The below script will enumerate an OU, pull the existing homedirectory variable and username for all users. Construct the new homedirectory location (with the username), rename the folders and then update the homedirectory field in AD.

 


'Usage: Modify the Container string below, then call the script using cscript from command prompt
'E.G. cscript renamehomes.vbs
'

'Global variables
Dim Container
Dim objShell

'Initialize global variables
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set Container=GetObject("LDAP://server/OU=Your,OU=Users,OU=Structure,,DC=Your,DC=Domain")
'*********
'********* Important, set the above line to reflect your OU setup. i.e LDAP://YOUR_FRDC/OU=Your_Users,DC=Your,DC=Domain
'*********

'Enumerate Container
EnumerateUsers Container

'Clean up
Set Container = Nothing

'Say Finished when your done
WScript.Echo "Finished"
WScript.Quit(0)

'List all Users
Sub EnumerateUsers(Cont)
Dim User

'Go through all Users and select them
For Each User In Cont
Select Case LCase(User.Class)

'If you find Users
Case "user"
Wscript.Echo "User = " & User.Name
'Initiate original user variables
OrigHome = User.HomeDirectory
AccountName = User.sAMAccountName
'Strip and concatenate orignal home and accountname to create newhome
NewHome = (Left(OrigHome,InStrRev(OrigHome,"\")))& AccountName
'Output 
Wscript.Echo "Original = " & OrigHome
Wscript.Echo "and " & AccountName
Wscript.Echo "Becomes " & NewHome

'Rename folder
objFSO.MoveFolder OrigHome , NewHome

'Update AD
User.Put "HomeDirectory", NewHome
User.SetInfo

Case "organizationalunit" , "container"
 EnumerateUsers User

End Select
Next
End Sub

 

Save the above as a vbscript and modify the container variable to suit your AD structure. Execute it from command prompt with cscript filename.vbs.

 

Matt

  • Thanks 1
Posted

Thank you, I'll give it a try shortly.

 

Would I be right in thinking that if I point it toward an OU with a test user in, then it would just apply to them?

 

Kind regards,

John.

Posted

That is indeed correct (and what i did while writing it).

 

Shouldn't matter if you run it on users that have the correct details either, as it will only replace with the original data.

 

Matt

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