Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AD Powershell的导入脚本_Powershell_Csv_Active Directory - Fatal编程技术网

AD Powershell的导入脚本

AD Powershell的导入脚本,powershell,csv,active-directory,Powershell,Csv,Active Directory,我在Active Directory的导入用户脚本方面遇到问题。在我添加员工ID、地址和SamAccountName之前,它就可以工作了。现在我收到了错误的语法错误。我可以得到一些帮助吗 脚本: # Create password for users $Password = ConvertTo-SecureString "Bevchain123$" -AsPlainText -Force # Inputing CSV file path $CSVlocation = Read-Host -P

我在Active Directory的导入用户脚本方面遇到问题。在我添加员工ID、地址和SamAccountName之前,它就可以工作了。现在我收到了错误的语法错误。我可以得到一些帮助吗

脚本:

# Create password for users
$Password = ConvertTo-SecureString "Bevchain123$" -AsPlainText -Force


# Inputing CSV file path
$CSVlocation = Read-Host -Prompt "Enter path to CSV file"

# Puttting file into a variable
$users = Import-Csv $CSVlocation 




#Create for each function to grab data from CSV file

foreach ($user in $users)  {

#Frist name
$FirstName = $user.'First Name'  

#Last name
$LastName = $user.'Last Name' 

#description
#$Description = $user.Description

#Orginisational Unit Path
$OUpath = $user.Unit 

$EmployID = $user.'Personal Number'

$Address = $user.Address

$aaccount = $user.Samaccountname

# Create the Active Directory user for each line of the CSV

NEW-ADUser -Name "$FirstName $LastName" -EmployeeID "$EmployID" -SamAccountName "$aaccount" -GivenName "$FirstName" -StreetAddress "$Address" -UserPrincipalName "$FirstName.$LastName"  -AccountPassword $Password -ChangePasswordAtLogon $false -Path $OUpath


# Message output to screen

Echo "user created successfully for: $FirstName in path: $OUpath"

}
错误消息:

NEW-ADUser : The object name has bad syntax
At C:\Users\Administrator\Desktop\Scripts\Import Users.ps1:41 char:1
+ NEW-ADUser -Name "$FirstName $LastName" -EmployeeID "$EmployID" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (CN=Brendan Week...vTest,DC=Local":String) [New-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADUser
CSV格式:

First Name,Last Name,Address,Personal Number,Unit,Samaccountname
Test,User01,123 Test Street,000001,"OU=TestOU,DC=TestDC,DC=Local",Tuser01
Test,User02,123 Test Street,000002,"OU=TestOU,DC=TestDC,DC=Local",Tuser02

您是否已尝试删除添加的每个变量,以查看哪一个是问题所在,也可能将整个新ADUser行写入控制台,可能会提示您出了什么问题。我现在已经尝试过,如果我手动输入用户,它会工作,但是脚本不会运行,即使它只是-Name和-Path。您确定目标OU存在并且可用吗?错误看起来好像是说完整的对象名无效。我的csv中有额外的,s我的错误谢谢大家。