Saya mengambil jawaban Brad di atas dan menambahkan sedikit lebih detail di bawah ini (terima kasih Brad karena membuat saya berpikir ke arah ini):
Input file CSV:
cn,givenname,sn,sAMAccountName,displayname,UserPrincipalName
Joe Smith,Joe,Smith,jsmith,Joe Smith,jsmith@domain.com
Susan Johnson,Susan,Johnson,sjohnson,Susan Johnson,sjohnson@domain.com
Kode:
$inputFile = Import-CSV <insert filepath here>
foreach($line in $inputFile)
{
## need to add quotes around DSN
$dsn = "`"cn="+$line.cn+",ou=userou,dc=domain,dc=com`""
$samid = $line.sAMAccountName
$ln = $line.sn
$fn = $line.givenname
$dn = $line.displayname
## need to add quotes around display name
$dn2 = "`"$dn`""
$upn = $line.UserPrincipalName
cmd /c "dsadd user $dsn -samid $samid -ln $ln -fn $fn -display $dn2
-upn $upn -mustchpwd yes -pwd TempP@assw0rd"
write-host `n
}
Semoga berhasil!