简体   繁体   English

为 AD 用户创建新的配置文件路径

[英]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:你在这里发生了几件事:

  • You need to specify the share name in the UNC path between the server name and share path.您需要在服务器名称和共享路径之间的 UNC 路径中指定共享名称。 Administrative shares are automatically created for attached storage by default (such as for the C: ), and the drive letter is suffixed with a $ .默认情况下会为附加存储自动创建管理共享(例如C: ),并且驱动器号以$为后缀。
    • You do not need to escape the $ since the proceeding \ will not be parsed as part of a variable name您不需要转义$因为程序\不会被解析为变量名的一部分
  • You forgot the last octet of the IP when setting $HomePath设置$HomePath时忘记了 IP 的最后一个八位字节
  • While not an issue, we can use the $StandardPath variable to build the other two虽然不是问题,但我们可以使用$StandardPath变量来构建另外两个
  • Both 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中指定的目录下创建另一个目录,该目录已经创建了所有缺失的目录。
  • You can also simply use $ProfilePath to create the $Username directory, since the path is the same as $StandardPath\$Username您也可以简单地使用$ProfilePath创建$Username目录,因为该路径与$StandardPath\$Username相同
  • You don't need to use $($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 a CIFS share from a single server.警告:如果您必须使用漫游配置文件,请通过DFS或至少一个适当的存储设备支持它们,而不是来自单个服务器的CIFS共享。 Also don't use the IP, use the NetBIOS , DNS , or FQDN name in the UNC path.也不要使用 IP,在UNC路径中使用NetBIOSDNSFQDN名称。 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM