Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$adPath = 'OU=Users,OU=Dev,DC=test,DC=local'
$adDomain = 'test.local'
$userPassword = 'aV3ryl0ng-and.securePASSWORD!!'
$users = Get-RandomUser -Amount 30 -Nationality gb,uk -ExcludeFields picture | Select-Object -ExpandProperty results
foreach ($user in $users) {
$newUserProperties = @{
Name = "$($user.name.first) $($user.name.last)"
GivenName = $user.name.first
Surname = $user.name.last
Path = $adPath
AccountPassword = (ConvertTo-SecureString $userPassword -AsPlainText -Force)
SamAccountName = $user.login.username
UserPrincipalName = "$($user.login.username)@$($adDomain)"
Enabled = $true
}
try {New-ADUser @newUserProperties} catch {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment