공부/Windows
[Active Directory] PowerShell로 AD OU/User 생성하기 ( + CSV)
haejang
2021. 10. 3. 22:13
728x90
728x90
AD OU 생성
New-ADOrganizationalUnit -Name "honglab_ou" -Path "OU=DOMAIN,DC=DOMAIN,DC=com"
AD User 생성
New-ADUser -DisplayName "honglab" -AccountPassword $(ConvertTo-SecureString -AsPlainText "Password#1" -Force) -Name "honglab" -EmailAddress "honglab97@gmail.com" -GivenName "HaeJang" -Surname "Hong" -UserPrincipalName "honglab@DOMAIN.com" -ChangePasswordAtLogon $True -Path "OU=honglab_ou,OU=DOMAIN,DC=DOMAIN,DC=com"
CSV에서 바로 User 생성
Import-Csv .\ad_user.csv | foreach-object{
New-ADUser -Name $_.Full_Name -EmailAddress $_.Email -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -DisplayName $_.Full_Name -GivenName $_.First_Name -Path $_.Path -Surname $_.Last_Name -UserPrincipalName $_.Logon_Name -ChangePasswordAtLogon $True
}
ad_user.csv
Batch 사용해서 일괄적으로 추가하기
run_ps.bat
@echo off
Powershell.exe -executionpolicy remotesigned -File .\add_ad_user.ps1
pause
add_ad_user.ps1
New-ADOrganizationalUnit -Name "honglab_ou" -Path "OU=DOMAIN,DC=DOMAIN,DC=com"
Import-Csv .\ad_user.csv | foreach-object{
New-ADUser -Name $_.Full_Name -EmailAddress $_.Email -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -DisplayName $_.Full_Name -GivenName $_.First_Name -Path $_.Path -Surname $_.Last_Name -UserPrincipalName $_.Logon_Name -ChangePasswordAtLogon $True
}
Ref
https://community.spiceworks.com/topic/541380-adding-users-via-new-aduser-and-a-csv-file
728x90
728x90