3

新しい Windows 2008 サーバー ローカル ユーザーを作成し、そのユーザーに別のプロファイル パスを割り当てようとしています。Windows が C:\Users\newUser の下にすべてのファイルを生成するのではなく、D:\customDir\newUser でそれを実行するようにしたいと考えています。これを行う方法を知っている人はいますか?

これまでのところ、これは私が持っているものです:

$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 does not work, throws an error
    #$user.put("homeDirDrive","D:") #This appears to be ignored when uncommented
    $user.setpassword($userName)
    $user.setInfo()

    $group.add($user.Path)

    #run cmd from user account to 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

}

スクリプトはユーザーを正常に作成してカスタム グループに追加しますが、すべてのファイル/フォルダーは最終的に C:\Users\U* になります。

4

4 に答える 4

5

OPに、

この作品のおかげで、私は自分のためにこれを機能させる方法を見つけようとしていました:

ユーザー アカウントから cmd を実行して、プロファイル ファイル/フォルダーを作成します。

$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

しかし、それを機能させるには最後の行を変更する必要がありました:

Start-Process cmd /c -Credential $cred -ErrorAction SilentlyContinue -LoadUserProfile
于 2013-10-09T21:00:15.100 に答える