方法一:导入csv
Import-csv -Path C:\users.csv | foreach { New-ADUser -SamAccountName $_.SamAccountName -name $_.name -Enabled $true -GivenName $_.GivenName -Surname $_.surname -UserPrincipalName $_.UserPrincipalName -AccountPassword (ConvertTo-SecureString -AsPlainText "xxxx" -Force) }
方法而:单用户导入
$SamAccountName = "xxxxxx" #不能重复
$Surname = "xx"
$GivenName = "xxx"
$Name = $Surname+$GivenName #不能重复
$Name
$DisplayName =$Surname+$GivenName
$DisplayName
$UserPrincipalName = $SamAccountName + "@xxxx.com"
$UserPrincipalName
$Description = "Data.user"
$password = "xxxx"
New-ADUser -SamAccountName $SamAccountName -GivenName $GivenName -Name $Name -Surname $Surname -DisplayName $DisplayName -Enabled $true -UserPrincipalName $UserPrincipalName -Path "ou=xx,dc=xxxx,dc=com" -AccountPassword (ConvertTo-SecureString -AsPlainText $password -Force) -Description $Description