从csv文件导入Active Directory批量导入

时间:2017-03-16 15:18:32

标签: powershell csv active-directory bulk-import

我正在尝试使用以下代码在Active Directory中批量导入所有客户 OU。

$Users = Import-Csv -Delimiter "`t" -Path "C:\AnnexA.csv"
foreach ($User in $Users)
{
$Displayname = $User.Forenames + " " + $User.Surname
$UserFirstname = $User.Forenames
$UserLastname = $User.Surname
$OU = "OU=All Customers,DC=PentagonMoon,DC=local"
$SAM = $User.Forenames + "." + $User.Surname
$Town = $User.Town
$Street =$User.Address
$Postcode = $User.Postcode
$Telephone = $User.Telephone
$Email = $User.email

New-ADUser -Name $Displayname
-DisplayName $Displayname
-SamAccountName $SAM
-UserPrincipalName $UPN
-GivenName $UserFirstname
-Surname $UserLastname
-City $Town
-StreetAddress $Street
-PostalCode $Postcode
-HomePhone $Telephone
-EmailAddress $Email
-AccountPassword (ConverTo-SecureString - AsPlainText Password123 - Force)
-Enabled $true -Path "$OU"
-ChangePasswordAtLogon $false
-PasswordNeverExpires $true
}

CSV文件包含Surname,Forenames,Address,Town,Postcode,Telephone,email titles。我收到了一些错误,但看不出代码有什么问题。

1 个答案:

答案 0 :(得分:0)

我不知道它是否是唯一的问题,但是:

-AccountPassword (ConverTo-SecureString - AsPlainText Password123 - Force)

应该是

-AccountPassword (ConvertTo-SecureString -AsPlainText Password123 -Force)