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

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

本文介绍了提供的姓名名称格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 "[email protected]" `
        -Name $Firstname $Lastname `
        -GivenName $Firstname `
        -Department "$Department" `
        -Company "$Company" `
        -EmailAddress "[email protected]" `
        -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.net'"
'GivenName' = "$User.FNAME"
'SurName' = "$User.LNAME"
'EmailAddress' = "$User.ID = '@clasd.net'"
'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.ps1CN=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.LNAMENew-ADUser : The name provided is not a properly formed account nameAt 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

这篇关于提供的姓名名称格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 08:36