[英]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.