【发布时间】:2021-08-19 04:28:24
【问题描述】:
我正在制作一个用于创建新 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
有人可以帮帮我吗?
【问题讨论】:
-
您不会忘记 $StandardPath 中的驱动器号吗?
"\\192.168.1.32\$driveLetter\Users"?附言最好不要使用(在这种情况下混合使用)大引号“并始终使用直引号。还要确保您的变量$Username不包含无效的文件夹名称字符 -
天哪,你对驱动器字母的看法是对的,我完全忘记了这一点。
-
不要忘记管理驱动器号共享也以
$为后缀。
标签: powershell active-directory