提供的姓名名称格式不正确

编程入门 行业动态 更新时间:2024-10-26 16:32:20
本文介绍了提供的姓名名称格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以帮助我遇到另一个错误吗?

Can someone help with another error I'm experiencing?

我的创建用户脚本给了我另一个错误.

My create user script is giving me another error.

foreach ($User in $ADUsers) { #Read user data from each field in each row and assign the data to a variable as below $Username = $User.ID $Password = $User.BDATE $Firstname = $User.FNAME $Lastname = $User.LNAME $Department = $User.GRD $Company = $User.SCHID #This field refers to the OU the user account is to be moved to # Choose OU switch ($Company) { "1480" {$OU = 'OU=students,OU=users,ou=hs,dc=clasd,dc=net'} "1479" {$OU = 'OU=students,OU=users,ou=elem,dc=clasd,dc=net'} "1480" {$Folder = '\\hs-ss\students\hs'} "1479" {$Folder = '\\hs-ss\students\elem'} } #Account will be created in the OU provided by the $OU variable read from the CSV file New-ADUser ` -SamAccountName $Username ` -UserPrincipalName "$Username@clasd" ` -Name $Firstname $Lastname ` -GivenName $Firstname ` -Department "$Department" ` -Company "$Company" ` -EmailAddress "$Username@clasd" ` -Surname $Lastname ` -Enabled $True ` -Scriptpath "login.vbs" ` -DisplayName "$Firstname $Lastname" ` -Path $OU ` -Homedrive "Z" ` -homedirectory "$Folder\$username" ` -AccountPassword (ConvertTo-SecureString "$User.BDATE" -AsPlainText -Force) ` -ChangePasswordAtLogon $true }

我的错误是:

New-ADUser : The name provided is not a properly formed account name At C:\AD_Scripts\psscripts\user_create.ps1:34 char:9 + New-ADUser ` + ~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (CN=\\ ,OU=stude...dc=clasd,dc=net:String) [New-ADUser], ADException + FullyQualifiedErrorId : The name provided is not a properly formed account name,Microsoft.ActiveDirectory.Management.Commands.NewADUser

编辑1

如果我 Write-Host $ Firstname $ Lastname ,我得到正确的"User2 User2".

If I Write-Host $Firstname $Lastname I get "User2 User2" which is correct.

编辑2

即使收到我收到的消息,帐户仍然会创建.

The account still gets created even with that message I receive.

编辑3

我已经继续前进,并像我被告知那样散布一些东西.我仍然在同一个错误中挣扎.仅这次用户没有被创建.

I've gone ahead and splatted things like I've been told. I'm still struggling with the same error though. Only this time the user does NOT get created.

# Import active directory module for running AD cmdlets Import-Module activedirectory #Store the data from ADUsers.csv in the $ADUsers variable $ADUsers = Import-csv userimport.csv #Store report in log file in the $log variable $log = "log.txt" #Set Additional Variables $Password = (ConvertTo-SecureString -AsPlainText "$User.BDATE" -Force) $DisplayName = "$User.FNAME+ ' ' + $user.LNAME" $Company = $User.SCHID # Choose OU Switch ($Company) { "1480" {$OU = 'OU=students,OU=users,ou=hs,dc=clasd,dc=net'} "1479" {$OU = 'OU=students,OU=users,ou=elem,dc=clasd,dc=net'} "1480" {$Folder = '\\hs-ss\students\hs'} "1479" {$Folder = '\\hs-ss\students\elem'} } Write-Host $DisplayName #Create Hash Table for New User Creation $ADUsers = @{ 'SamAccountName' = "$User.ID" 'UserPrincipalName' = "$User.ID + '@clasd'" 'GivenName' = "$User.FNAME" 'SurName' = "$User.LNAME" 'EmailAddress' = "$User.ID = '@clasd'" 'Path' = $OU 'Department' = "$User.GRD" 'Company' = "$User.SCHID" 'AccountPassword' = $Password 'ChangePasswordAtLogon' = $true 'Enabled' = $true 'DisplayName' = "$DisplayName" 'Name' = $Displayname } #Call New-ADUser with the parameters Above Foreach ($User in $ADUsers) { New-ADUser @ADUsers}

PS C:\ AD_Scripts \ psscripts>.\ Untitled1.ps1CN = User2 User2,OU =学生,OU = Users,OU = Elem,DC = clasd,DC = net.FNAME +''CN = User2 User2,OU = Students,OU = Users,OU = Elem,DC = clasd,DC = net.LNAMENew-ADUser:提供的名称不是正确格式的帐户名在C:\ AD_Scripts \ psscripts \ Untitled1.ps1:48 char:1+ New-ADUser @ADUsers}+ ~~~~~~~~~~~~~~~~~~~+ CategoryInfo:未指定:(CN = CN \ = User2 Us ... dc = clasd,dc = net:String)[New-ADUser],ADException+ FullyQualifiedErrorId:提供的名称不是正确格式的帐户名Microsoft.ActiveDirectory.Management.Commands.NewADUser

PS C:\AD_Scripts\psscripts> .\Untitled1.ps1 CN=User2 User2,OU=Students,OU=Users,OU=Elem,DC=clasd,DC=net.FNAME+ ' ' + CN=User2 User2,OU=Students,OU=Users,OU=Elem,DC=clasd,DC=net.LNAME New-ADUser : The name provided is not a properly formed account name At C:\AD_Scripts\psscripts\Untitled1.ps1:48 char:1 + New-ADUser @ADUsers} + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (CN=CN\=User2 Us...dc=clasd,dc=net:String) [New-ADUser], ADException + FullyQualifiedErrorId : The name provided is not a properly formed account name,Microsoft.ActiveDirectory.Management.Commands.NewADUser

推荐答案

我已将Powershell更新为版本4,并且在发布的原始脚本中不再收到任何错误.以前我使用的是Ver 3

I've updated powershell to version 4 and I no longer receive any errors in my original script that I posted. Previously I was using Ver 3

更多推荐

提供的姓名名称格式不正确

本文发布于:2023-11-09 15:14:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   姓名   名称   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!