我試圖創建一個新的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