+ Post New Thread
Results 1 to 10 of 10
Windows Server 2008 Thread, Script to modify profile path in Technical; Has anyone got a nice simple script that will let me modify all users (in an AD container) profile path? ...
  1. #1
    Sheridan's Avatar
    Join Date
    Oct 2010
    Posts
    1,161
    Thank Post
    89
    Thanked 84 Times in 56 Posts
    Rep Power
    28

    Script to modify profile path

    Has anyone got a nice simple script that will let me modify all users (in an AD container) profile path?

    I need to take their existing profile path, and add a bit and then save it!

  2. #2
    etz
    etz is offline

    Join Date
    Feb 2013
    Posts
    4
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0
    I might be being obtuse here, but can't you bulk select the users in AD, then right click properties and put the new profile path in, in the format of \\server-name\share\%username%\additionaldooberrieshere ?

  3. #3

    Join Date
    Jul 2012
    Location
    Boerne Texas USA
    Posts
    41
    Thank Post
    0
    Thanked 9 Times in 9 Posts
    Rep Power
    5
    dsquery user ou=somewhere,dc=over,dc=net | dsmod user -profile users\$username$\profile

    if it is more complicated then you could send the existing info to a txt file, edit it, and then use it as input to script to make the change. see dsquery | dsmod
    for an example (uses telephone but you could do profile)

    Or could use powershell.

  4. #4
    Sheridan's Avatar
    Join Date
    Oct 2010
    Posts
    1,161
    Thank Post
    89
    Thanked 84 Times in 56 Posts
    Rep Power
    28
    Problem is the user names have been manually entered (not my system!) so I need to read the existing profile path and then add to it and resave it. The usernames don't always follow a convention either!

  5. #5

    Join Date
    Jul 2012
    Location
    Boerne Texas USA
    Posts
    41
    Thank Post
    0
    Thanked 9 Times in 9 Posts
    Rep Power
    5
    Can you give me more concrete examples?

  6. #6
    Sheridan's Avatar
    Join Date
    Oct 2010
    Posts
    1,161
    Thank Post
    89
    Thanked 84 Times in 56 Posts
    Rep Power
    28
    Well, in the profile path we can have \\server\path\johnsmith or \\server\path\jsmith or even \\server\path\john_smith. These have all been created manually by someone in the past. We need to append a subfolder to each profile path and save it. The %username% variable wasn't used unfortunately

  7. #7

    Join Date
    Jul 2012
    Location
    Boerne Texas USA
    Posts
    41
    Thank Post
    0
    Thanked 9 Times in 9 Posts
    Rep Power
    5
    And you can't or don't want to fix the inconsistency of username not being a part of the profile path?

    If not checkout the link in my prior post to use the dsquery command to output to a text file the existing profile path, edit the file, and then use the file as input to a for command loop that runs the dsmod command to save the new profile path in AD.

    Or maybe do it in powershell. http://techsugar.wordpress.com/2012/...ng-powershell/

    PS. When using the dsmod command you use $username$ not %username% to represent the username on the account. dsmod user /q to see more
    Last edited by jklight; 5th February 2013 at 01:25 PM.

  8. #8

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Not sure here but would one of the utils from WiseSoft - Resources for IT Professionals ( free registration ) not allow you to do this ?

    FAQ from wisesoft site : http://www.wisesoft.co.uk/forum/topi...-username.aspx

    ie : Bulk AD Users - Bulk Modify

  9. #9
    Sheridan's Avatar
    Join Date
    Oct 2010
    Posts
    1,161
    Thank Post
    89
    Thanked 84 Times in 56 Posts
    Rep Power
    28
    Hmm, I think dsquery and dsmod might be the quickest way to fettle this. Its a one off and I'm not changing their setup (just helping an associate school thats all)

  10. Thanks to Sheridan from:

    mac_shinobi (5th February 2013)

  11. #10
    Duke5A's Avatar
    Join Date
    Jul 2010
    Posts
    731
    Thank Post
    74
    Thanked 113 Times in 99 Posts
    Blog Entries
    8
    Rep Power
    27
    If you're still plugging away at this, give this a try:

    Code:
    Const strHomeDrive = "H"
    Const strHomePath = "\\server\basehomeshare\"
    
    Dim strFailLog
    
    Call Main
    Call WriteLog
    
    Sub Main
    
    	Set oContainer = GetObject("LDAP://OU=Users,DC=domain,DC=com")
    	oContainer.Filter = Array("user")
    
    	For Each User in oContainer
    		
    		strName = User.samaccountname
    				
    		If CheckPathExist(strName) = True Then
    			User.Put "homedrive", strHomeDrive 
    			User.Put "homedirectory", strHomePath & strName
    			User.SetInfo
    		Else
    			strFailLog = strName & " | " & strFailLog
    		End If
    
    		WScript.Sleep 70
    	
    	Next
    
    	Msgbox "Jobs Done!"
    	
    End Sub
    	
    Sub WriteLog
    
    	strFileName = "LogFile.txt"
    	
    	Set objFileSys = CreateObject("Scripting.FileSystemObject")
    	Set objFile = ObjFileSys.CreateTextFile(StrFileName)
    	
    	objFile.Write(strFailLog)
    	objFile.Close
    
    End Sub	
    	
    Function CheckPathExist(strName)
    
    	Set objFileSys = CreateObject("Scripting.FileSystemObject")
    	blnExists = objFileSys.FolderExists(strHomePath & strName)
    	CheckPathExist =  blnExists	
    
    End Function
    I used this to bulk change the base the home folder path a few years ago when we changed the staff home folder location. It might take some editing to make it work for you. The way it is setup it assumes you have one top level share with folders under that named according to account name. I hope this helps.
    Last edited by Duke5A; 12th February 2013 at 06:29 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 13
    Last Post: 22nd February 2013, 03:53 PM
  2. Script to delete profile at log off?
    By woody in forum Windows
    Replies: 74
    Last Post: 15th February 2013, 02:28 PM
  3. Logon script to change profile?
    By garethedmondson in forum Windows 7
    Replies: 1
    Last Post: 4th March 2010, 08:28 PM
  4. Replies: 0
    Last Post: 20th August 2007, 02:20 PM
  5. Replies: 6
    Last Post: 16th September 2006, 09:33 PM

Thread Information

Users Browsing this Thread

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

Posting Permissions

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