我正在尝试创建一个新的 Win 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*