[英]Creating new Profilepath for AD User
I'm making a script in which a new AD user gets created.我正在制作一个脚本,其中创建了一个新的 AD 用户。 I also want to give it a Profilepath and a Homepath.我还想给它一个 Profilepath 和一个 Homepath。 But I always get a error when I run this part were I try to create a new Profilepath and Homepath.但是当我尝试创建一个新的 Profilepath 和 Homepath 时,当我运行这部分时总是会出错。 Thats my Script:那是我的脚本:
$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
And here Is the Error:这是错误:
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
Can somebody help me?有人可以帮我吗?
You have a few things going on here:你在这里发生了几件事:
C:
), and the drive letter is suffixed with a $
.默认情况下会为附加存储自动创建管理共享(例如C:
),并且驱动器号以$
为后缀。
$
since the proceeding \
will not be parsed as part of a variable name您不需要转义$
因为程序\
不会被解析为变量名的一部分$HomePath
设置$HomePath
时忘记了 IP 的最后一个八位字节$StandardPath
variable to build the other two虽然不是问题,但我们可以使用$StandardPath
变量来构建另外两个New-Item
invocations can omit the -Name
parameter since you have the directory paths specified in the -Path
variable.两个New-Item
调用都可以省略-Name
参数,因为您在-Path
变量中指定了目录路径。 Using the -Name
parameter will create another directory under the directory specified in -Path
, which will already create any missing directories.使用-Name
参数将在-Path
中指定的目录下创建另一个目录,该目录已经创建了所有缺失的目录。$ProfilePath
to create the $Username
directory, since the path is the same as $StandardPath\$Username
您也可以简单地使用$ProfilePath
创建$Username
目录,因为该路径与$StandardPath\$Username
相同$($Username)
for expanding a single variable.您不需要使用$($Username)
来扩展单个变量。 You can omit the sub-expression operator $()
entirely.您可以完全省略子表达式运算符$()
。The below corrections should work for you:以下更正应该对您有用:
Warning: If you must use roaming profiles, back them by
DFS
or at least a proper storage appliance, not aCIFS
share from a single server.警告:如果您必须使用漫游配置文件,请通过DFS
或至少一个适当的存储设备支持它们,而不是来自单个服务器的CIFS
共享。 Also don't use the IP, use theNetBIOS
,DNS
, orFQDN
name in theUNC
path.也不要使用 IP,在UNC
路径中使用NetBIOS
、DNS
或FQDN
名称。 If that server goes down or the IP changes your user on that system will have issues the profile not synchronizing correctly, and roaming profiles can be fickle when it comes to sync issues.如果该服务器出现故障或 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.