Announcement

Collapse
No announcement yet.

Script that will Scan AD users and change specific part of home directory

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script that will Scan AD users and change specific part of home directory

    I've been looking for a script that will scan all users in active directory, and change a specific part of their home directory. For example:

    //backupserver01/marketing/username

    to

    //backupserver02/marketing/username


    The change is only applied to backupserver.

    I have googled this and have not been successful finding anything. Does anyone know how to do this?

  • #2
    Re: Script that will Scan AD users and change specific part of home directory

    Assuming you have 2003 Server, why not do it in ADUC. Select all the users in that OU, right click, Properties, Profile, check Home folder and enter the home directory.
    1 1 was a racehorse.
    2 2 was 1 2.
    1 1 1 1 race 1 day,
    2 2 1 1 2

    Comment


    • #3
      Re: Script that will Scan AD users and change specific part of home directory

      But will that change a specific part of the home directory without effecting the other parts? Each user will have their own folder at the end:

      User1

      \\backupserver01\folder\user1

      to

      \\backupserver02\folder\user1

      But user 2 will have a different folder at the end...

      User2

      \\backupserver01\folder\user2

      to

      \\backupserver02\folder\user2

      So if I were to go in and change all of the home directories it wont make it specfic to the users that way...I think.

      Comment


      • #4
        Re: Script that will Scan AD users and change specific part of home directory

        Not sure if this is what you looking for:
        I've created this a long time ago with support from microsoft site

        Code:
        Set ObjOU= GetObject ("LDAP://OU=Test,DC=domain,DC=local")
        
        For Each ObjUser In ObjOU
         Home=ObjUser.HomeDirectory
         WScript.Echo home
               On Error Resume next
                   If Left (UCase(home),12) = "\\SERVER001\" then
                          home =Replace (UCase (home) ,"\\SERVER001\","\\SERVER002\")
                          WScript.Echo home 
                   End If
               ObjUser.Put "HomeDirectory" , home
               ObjUser.SetInfo
        Next
        Set objOU = Nothing
        MOD: I think you should move this one to the scripting forum...

        MAKE Sure that you test it carefully. Also I'm not responsible for any errors. This worked for me when we migrated from NT4 to 2000.
        Last edited by Dumber; 27th October 2006, 14:13.
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: Script that will Scan AD users and change specific part of home directory

          Yes that looks like what I want to do, thanks. I will test it out.

          Comment


          • #6
            Re: Script that will Scan AD users and change specific part of home directory

            How would I put in my OU and domain, I'm a little confused on setting this part up. Lets say my domain is:

            domain.my-domain.com

            and the OU in order of the tree is like this:

            My Company
            Departments
            Information Technolgy
            Users (not sure if this is there by default)

            Would this be how its set up: ?

            Set ObjOU= GetObject ("LDAP://OU=My Company,OU=Departments,OU=Information Technology,OU=Users,DC=domain,DC=my-domain,DC=com")

            Comment


            • #7
              Re: Script that will Scan AD users and change specific part of home directory

              I'll move this to the scripting forum.

              Comment


              • #8
                Re: Script that will Scan AD users and change specific part of home directory

                I assume there are no actual users in the users OU, just the 3 OU's
                I would put every OU in an array and loop through it all like this:

                Code:
                arrOU = array("My Company","Departments","Information Technolgy")
                
                for each OUsection in arrOU
                
                	Set ObjOU= GetObject ("LDAP://OU="&OUsection&",OU=Users,DC=domain,DC=my-domain,DC=com")
                
                	For Each ObjUser In ObjOU
                Home=ObjUser.HomeDirectory
                 WScript.Echo home
                       On Error Resume next
                           If Left (UCase(home),12) = "\\SERVER001\" then
                                  home =Replace (UCase (home) ,"\\SERVER001\","\\SERVER002\")
                                  WScript.Echo home 
                           End If
                       ObjUser.Put "HomeDirectory" , home
                       ObjUser.SetInfo
                Next
                Set objOU = Nothing
                
                next
                
                MsgBox("The script is ready!!")
                think that should be it.

                Comment


                • #9
                  Re: Script that will Scan AD users and change specific part of home directory

                  No all the users do reside in the Users OU.

                  Comment


                  • #10
                    Re: Script that will Scan AD users and change specific part of home directory

                    So you have all your users in default Users container, not OU, because you can't create an OU with the name Users, if i'm correct.
                    And you have a couple users in the OU's ?

                    Maybe you can give a little more info on how you designed your users setup.

                    Comment


                    • #11
                      Re: Script that will Scan AD users and change specific part of home directory

                      There are tons of other OU's that I have, but I want to change this particular department. So yes they are in the default users container, not in the other OU's that I listed. So its like this:

                      My Company
                      Departments (there are other OU's in here but only choosing Information Tech)
                      Information Technology
                      Users (all users are in here, around 20)


                      Does that clear it up?

                      Comment


                      • #12
                        Re: Script that will Scan AD users and change specific part of home directory

                        I was reading through the complete post again.
                        And i was thinking, why not appy the method Biggles said and to use the specific path use
                        \\backupserver02\folder\%username%

                        Then normally the variable is changed to the specific username.

                        Did you give that a try ?

                        Comment


                        • #13
                          Re: Script that will Scan AD users and change specific part of home directory

                          Yeah I thought about that too but I wasn't sure if that was going to work. I can put that in there but I still don't know the right way to put in my OU and DC.

                          Comment


                          • #14
                            Re: Script that will Scan AD users and change specific part of home directory

                            Don't exactly know what you mean but..

                            Just select all the users where you want to change the homefolder.
                            You wanted to change the homefolder of the IT OU.
                            Open the IT container, select all users in there and appy the changes.

                            This goes way faster then breaking your head on constructing a descent working vbs.

                            Comment


                            • #15
                              Re: Script that will Scan AD users and change specific part of home directory

                              OOOOOOH I gotcha, throught that way and not a script. Ok I will see if that works.

                              Comment

                              Working...
                              X