有人可以幫助我遇到另一個錯誤嗎?提供名稱不正確的帳戶名稱
我的創建用戶腳本給了我另一個錯誤。
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
我得到 「用戶2用戶2」,這是正確的。
EDIT 2
仍然會變得與該消息我收到創建的帳戶。
編輯3
我已經先行一步就像我已經告訴splatted事情。儘管如此,我仍然在努力解決同樣的問題。只有這一次用戶不會被創建。
# 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.ps1 CN =用戶2用戶2,OU =學生,OU =用戶,OU = ELEM,DC = clasd,DC = net.FNAME + '' + CN = User2 User2,OU = Students,OU = Users,OU = Elem,DC = clasd,DC = net.LNAME 新ADUser:提供的名稱不是正確形成的帳戶名稱 在C:\ AD_Scripts \ psscripts \ Untitled1.ps1:48 char:1 + New-ADUser @ADUsers} + ~~~~~~~~~~~~~~~(CN = User2 Us ... dc = clasd,dc = net:String)[New-ADUser],ADException + FullyQualifiedErrorId:提供的名稱不是正確形成的帳戶名稱,Microsoft.ActiveDirectory.Ma nagement.Commands.NewADUser
再次問好,首先想問你是否最終解決了密碼問題,剛纔看到你最近的評論。其次,你可以在'New-ADUser'之前做一個'Write-Host $ username'嗎?驗證$ UserName變量是否包含您期望的數據? –
嘗試'-Name「$ Firstname $ Lastname」' –
@AustinFrench你的答案仍然給我同樣的錯誤/消息 –