Powershell script to create Bulk User Accounts and add them to AD group in parllel.
Purpose: Request to Create bulk user accounts like 100+ for testing and add to AD Group
Comment for improvement
Script:
Import-Module ActiveDirectory
$totalusers = <Provide the no of users you want to create, Ex: 50>
for ($i=0; $i -lt $totalusers; $i++)
{
$userID = "{0:00}" -f ($i + 1)
//below is cmd to user account name like Test01, Test02...etc; change the cmd according to the format.
$userName = "Test$userID"
Write-Host "Creating AD user" ($i + 1) "of" $totalusers ":" $userName
New-ADUser -Name $userName -Path "<OU path to create user Account;ex:CN=Users,DC=XX,DC=XXXXX,DC=XXX" -SamAccountName $userName -AccountPassword (ConvertTo-SecureString "<EnterPassword>" -AsPlainText -Force) -ChangePasswordAtLogon $false -Enabled $true -Description "Description of the Account" -Notes "<any notes if you would like to add>" -PasswordNeverExpires $True -UserPrincipalName $_."userName" + "@<DomainName,ex:XXXXXX.com>" -GivenName $userName -DisplayName $userName
//you can comment out below line, if you wouldn't like to add user to any ad group
Add-ADGroupMember "<AD group name to add User to>" $userName;
}
Purpose: Request to Create bulk user accounts like 100+ for testing and add to AD Group
Comment for improvement
Script:
Import-Module ActiveDirectory
$totalusers = <Provide the no of users you want to create, Ex: 50>
for ($i=0; $i -lt $totalusers; $i++)
{
$userID = "{0:00}" -f ($i + 1)
//below is cmd to user account name like Test01, Test02...etc; change the cmd according to the format.
$userName = "Test$userID"
Write-Host "Creating AD user" ($i + 1) "of" $totalusers ":" $userName
New-ADUser -Name $userName -Path "<OU path to create user Account;ex:CN=Users,DC=XX,DC=XXXXX,DC=XXX" -SamAccountName $userName -AccountPassword (ConvertTo-SecureString "<EnterPassword>" -AsPlainText -Force) -ChangePasswordAtLogon $false -Enabled $true -Description "Description of the Account" -Notes "<any notes if you would like to add>" -PasswordNeverExpires $True -UserPrincipalName $_."userName" + "@<DomainName,ex:XXXXXX.com>" -GivenName $userName -DisplayName $userName
//you can comment out below line, if you wouldn't like to add user to any ad group
Add-ADGroupMember "<AD group name to add User to>" $userName;
}
No comments:
Post a Comment