+ Post New Thread
Results 1 to 9 of 9
Windows Thread, Renaming user profiles using a script and .csv in Technical; Hello, I have inherited a system that has two naming conventions for our pupils home directories. The newer one sensibly ...
  1. #1
    Johan's Avatar
    Join Date
    Sep 2009
    Posts
    26
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Renaming user profiles using a script and .csv

    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.

  2. #2
    User3204's Avatar
    Join Date
    Aug 2006
    Location
    Wirral
    Posts
    769
    Thank Post
    55
    Thanked 66 Times in 62 Posts
    Rep Power
    35
    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\ <username> ?
    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.

  3. #3
    Johan's Avatar
    Join Date
    Sep 2009
    Posts
    26
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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><initials><random number>). 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.

  4. #4

    Join Date
    Jul 2005
    Location
    Rugby
    Posts
    432
    Thank Post
    17
    Thanked 66 Times in 61 Posts
    Rep Power
    36
    Do all your users have the same username structure, and that's what you want to rename your older pupils home directories to?

    Matt

  5. #5
    Johan's Avatar
    Join Date
    Sep 2009
    Posts
    26
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    exactly.

  6. #6

    Join Date
    Jul 2005
    Location
    Rugby
    Posts
    432
    Thank Post
    17
    Thanked 66 Times in 61 Posts
    Rep Power
    36
    Give me a few minutes and i'll knock together a script.

  7. #7

    Join Date
    Jul 2005
    Location
    Rugby
    Posts
    432
    Thank Post
    17
    Thanked 66 Times in 61 Posts
    Rep Power
    36
    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.

    Code:
    '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

  8. Thanks to saundersmatt from:

    Johan (24th September 2009)

  9. #8
    Johan's Avatar
    Join Date
    Sep 2009
    Posts
    26
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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.

  10. #9

    Join Date
    Jul 2005
    Location
    Rugby
    Posts
    432
    Thank Post
    17
    Thanked 66 Times in 61 Posts
    Rep Power
    36
    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



SHARE:
+ Post New Thread

Similar Threads

  1. (Bulk) Change user passwords using csv
    By PEO in forum Windows Server 2008
    Replies: 2
    Last Post: 3rd June 2009, 01:50 PM
  2. PC user profiles
    By Millsy79 in forum Windows
    Replies: 2
    Last Post: 3rd March 2009, 04:15 PM
  3. user profiles
    By kevin_lane in forum Windows
    Replies: 4
    Last Post: 7th November 2008, 05:11 PM
  4. Replies: 6
    Last Post: 29th February 2008, 01:03 AM
  5. User profiles
    By speckytecky in forum How do you do....it?
    Replies: 3
    Last Post: 16th June 2006, 01:11 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •