Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $firstname = get-content C:\Script\firstnames
- $lastname = get-content C:\Script\lastnames
- $OU = "OU=Gothenburg,OU=Users,OU=LAB,DC=ad,DC=lab,DC=se", "OU=Stockholm,OU=Users,OU=LAB,DC=ad,DC=lab,DC=se", "OU=Malmo,OU=Users,OU=LAB,DC=ad,DC=lab,DC=se"
- $suffix = "lab.se"
- $department = "Sales", "Marketing", "Production", "Managers"
- if
- (get-adforest | ? UPNsuffixes -eq $suffix) {Write-Host "UPN Suffix $suffix already existing" -ForegroundColor Red}
- else {
- set-adforest -upnsuffixes @{add=$suffix} -Identity LAB
- Write-host "Created the suffix $suffix successfully" -ForegroundColor Green
- }
- 1..1000 | % {
- $randomOU = $OU | Get-Random
- $Randomfname = $firstname | Get-Random
- $Randomlname = $lastname | Get-Random
- $Randomfullname = $randomfname+" "+$randomlname
- $Randomdepartment = $department | Get-Random
- $UPN = $Randomfname.ToLower()+"."+$Randomlname.ToLower()+"@"+$suffix
- $randomyear = 53..99 | get-random
- $samaccountname = $Randomfname.substring(0,3)+$Randomlname.substring(0,3)+$randomyear
- $PrimaryProxyaddress = "SMTP:"+$UPN
- $SecondaryAddress = "smtp:"+$samaccountname+$suffix
- $securepassword = ConvertTo-SecureString -string "P@ssw0rd" -AsPlainText -force
- Write-Host "Creating user $Randomfullname with $UPN" -ForegroundColor Green
- $ADuser = New-ADuser `
- -name $Randomfullname `
- -AccountPassword $securepassword `
- -Enabled:$true `
- -path $randomOU `
- -UserPrincipalName "$UPN" `
- -samaccountname $samaccountname `
- -DisplayName $Randomfullname `
- -GivenName $Randomfname `
- -Surname $Randomlname `
- -emailaddress $UPN `
- -department $Randomdepartment `
- -Passthru
- Set-ADUser $ADuser -Add @{Proxyaddresses=$PrimaryProxyaddress,$SecondaryAddress}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement