Active Directory: Powershell 대량 계정생성

(Last Updated On: August 17, 2021)

ad powershell create user

$names = `u0001
u0002
u0003`

$securepassword = ConvertTo-SecureString "1q2w3e4r!" –asplaintext –force

$useroupath = "OU=KerusMembers,DC=kerus,DC=net"
Foreach ($name in $($names -split "`r`n")) {
    New-ADUser $name `
    -AccountPassword $securepassword `
    -DisplayName (Get-Culture).TextInfo.ToTitleCase($name) `
    -Path $useroupath `
    -Description "Powershell added" `
    -Enabled $true
    $UserIdentity = Get-ADUser -Identity "CN=$name,$useroupath"
    #Add-ADGroupMember -Identity "Domain Users" -Members $UserIdentity
}

remove user

Foreach ($name in $($names -split "`r`n")) {
    #remove-adgroupmember -Identity "Domain Users" -Members $name -Confirm:$false
    remove-aduser -Identity $name -Confirm:$false
}