[英]Creating new Profilepath for AD User
我正在制作一個腳本,其中創建了一個新的 AD 用戶。 我還想給它一個 Profilepath 和一個 Homepath。 但是當我嘗試創建一個新的 Profilepath 和 Homepath 時,當我運行這部分時總是會出錯。 那是我的腳本:
$StandardPath = "\\192.168.1.32\Users\"
$ProfilePath = “\\192.168.1.32\Users\$($Username)"
$HomePath = “\\192.168.1\Users\$($Username)\Home"
New-Item -path $StandardPath -Name $Username -ItemType Directory -force
Set-ADUser $Username -ProfilePath $ProfilePath
New-Item -path $Profilepath -Name "Home" -ItemType Directory -force
Set-ADUser $Username -HomeDrive $driveLetter -HomeDirectory $HomePath
這是錯誤:
New-Item : The path is not of a legal form.
At C:\Users\ewzadmin\Desktop\AddADUsers.ps1:47 char:9
+ New-Item -path $StandardPath -Name $Username -ItemType Direct ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\192.168.1.32\Users:String) [New-Item], ArgumentException
+ FullyQualifiedErrorId : CreateDirectoryArgumentError,Microsoft.PowerShell.Commands.NewItemCommand
有人可以幫我嗎?
你在這里發生了幾件事:
C:
),並且驅動器號以$
為后綴。
$
因為程序\
不會被解析為變量名的一部分$HomePath
時忘記了 IP 的最后一個八位字節$StandardPath
變量來構建另外兩個New-Item
調用都可以省略-Name
參數,因為您在-Path
變量中指定了目錄路徑。 使用-Name
參數將在-Path
中指定的目錄下創建另一個目錄,該目錄已經創建了所有缺失的目錄。$ProfilePath
創建$Username
目錄,因為該路徑與$StandardPath\$Username
相同$($Username)
來擴展單個變量。 您可以完全省略子表達式運算符$()
。以下更正應該對您有用:
警告:如果您必須使用漫游配置文件,請通過
DFS
或至少一個適當的存儲設備支持它們,而不是來自單個服務器的CIFS
共享。 也不要使用 IP,在UNC
路徑中使用NetBIOS
、DNS
或FQDN
名稱。 如果該服務器出現故障或 IP 發生更改,您在該系統上的用戶將遇到配置文件未正確同步的問題,並且在同步問題方面漫游配置文件可能會變化無常。
$StandardPath = "\\192.168.1.32\$driveletter$\Users"
$ProfilePath = "$StandardPath\$Username"
$HomePath = “$ProfilePath\Home"
New-Item -Path $ProfilePath -ItemType Directory -Force
Set-ADUser $Username -ProfilePath $ProfilePath
New-Item -Path $ProfilePath -ItemType Directory -Force
Set-ADUser $Username -HomeDrive $driveLetter -HomeDirectory $HomePath
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.