scripting - Create Local User with Custom User Folder in Powershell -


i trying create new win 2008 server local user , assign user different profile path. don't want windows generate files under c:\users\newuser, instead, i'd have in d:\customdir\newuser. know of way this?

so far have:

$users= @("u1","u2","u3") $computer = [adsi]"winnt://$env:computername,computer" $group = [adsi]"winnt://$env:computername/mycustomgroup,group" $users | foreach {     $username = $_     $userpath = "d:\customdir\$username"     echo "creating $username..."     $user = $computer.create("user",$username)     $user.put("description","user $username description")     #$user.put("profilepath",$userpath) #this not work, throws error     #$user.put("homedirdrive","d:") #this appears ignored when uncommented     $user.setpassword($username)     $user.setinfo()      $group.add($user.path)      #run cmd user account create profile files/folders     $spw = convertto-securestring $username -asplaintext -force     $cred = new-object system.management.automation.pscredential -argumentlist $username,$spw     start-process cmd /c -windowstyle hidden -credential $cred -erroraction silentlycontinue  } 

the script creates users , adds them custom group, files/folders end in c:\users\u*

the thing can think of change @ registry level. note i'm not recommending mess registry, want -

the default directory new profile determined profilesdirectory in hklm:\software\microsoft\windows nt\currentversion\profilelist, , default %systemdrive%\users, changing $userpath should want -

$regpath = "hklm:\software\microsoft\windows nt\currentversion\profilelist" $regname = "profilesdirectory"  set-itemproperty -path $regpath -name $regname -value $userpath 

hope helps!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -