我试图创建一个新的Win 2008服务器本地用户并为用户分配不同的配置文件路径。我不想让Windows生成C:\ Users \ newUser下的所有文件,相反,我想让它在D:\ customDir \ newUser中执行。有谁知道一种方法来做到这一点?使用Powershell中的自定义用户文件夹创建本地用户
到目前为止,这是我:
$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结束:\用户\ U *
您能否包含错误? – 2013-05-08 16:38:54
使用“2”参数调用“put”的异常:“来自HRESULT的异常:0x8000500F” 在行:1 char:1 + $ user.put(“profilePath”,“d:\ CustomDir \ U1”) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [] ,MethodInvocationException + FullyQualifiedErrorId:CatchFromBaseAdapterMethodInvokeTI – Farlan 2013-05-08 17:00:37