导入ad账号,需要两个账号,ps文件和csv文件

ps文件:

Import-Csv -Encoding Unicode user.csv |foreach-Object{  

$Nam=$_.name

$Givn=$_.givenname

$Surn=$_.surname

$Passw=$_.password

$Des=$_.description

$City=$_.city

$Emplyenum=$_.employeenumber

$Mobile=$_.mobilePhone

$com="@test.com"


$secure=ConvertTo-SecureString -string $Passw -asplaintext -force


New-ADUser -Name $Nam -SamAccountName $Nam -GivenName $Givn -Surname $Surn -Description $Des -DisplayName ($Surn+$Givn) -EmailAddress ($Nam+$com) -Enabled $true -PasswordNeverExpires $true -Path "OU=hr,DC=test,DC=com" -CannotChangePassword $false -ChangePasswordAtLogon $false  -AccountPassword $secure -UserPrincipalName ($Nam+$com) -HomePage "www.test.com" -EmployeeNumber $Emplyenum -MobilePhone $Mobile -City $City

}


csv文件

wKioL1agpGyB1RN1AABN9jnWNQ8201.png

放到同意目录下,运行ps脚本就可以添加用户。

下面的两条命令可以为添加的ad用户,启用邮箱

ps>Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

ps>Get-User -ResultSize unlimited -RecipientTypeDetails user| where {$_.userprincipalname -ne $null} |Enable-Mailbox -database mail1