Skip to content

Instantly share code, notes, and snippets.

@orlea
Created July 30, 2020 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlea/bfab0cb92d688a3e6646b2a82cdbb924 to your computer and use it in GitHub Desktop.
Save orlea/bfab0cb92d688a3e6646b2a82cdbb924 to your computer and use it in GitHub Desktop.
単一グループ単一OUに一括でADユーザ追加するやつ
Start-Transcript ((Get-Date).Tostring("yyyyMMdd")+".log") -Append
$userlist = Import-Csv .\userlist.csv
$password = ConvertTo-SecureString "default-password" -AsPlainText -Force
$ou = "OU=hoge,DC=fuga,DC=company,DC=co,DC=jp"
$group = "group-name"
for ($i = 0; $i -lt $userlist.Count; $i++) {
New-ADUser $userlist[$i].id -Surname $userlist[$i].id -DisplayName $userlist[$i].id -Path $ou -AccountPassword $password -Enabled $true
Add-ADGroupMember -Identity $group -Members $userlist[$i].id
}
Stop-Transcript
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
"id"
"lab-user1"
"lab-user2"
"lab-user3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment