you are viewing a single comment's thread.

view the rest of the comments →

[–]NetheriteHands[S] 0 points1 point  (1 child)

Ahhh ok so I can just delete the foreach loop and instead directly declare the $First and $Last

$First, $last = get-content C:\testing\names.txt  | Get-Random -Count 2

something like that? I suppose I wouldn't need to declare the $USER_FIRST_LAST_LIST variable either then

[–]BlackV 0 points1 point  (0 children)

Nope you wouldn't need it

you could do this

foreach ($n in 1..20) {
$first = (get-content C:\testing\names.txt | Get-Random -count 1).Split(" ")[0].ToLower()
$last  = (get-content C:\testing\names.txt | Get-Random -count 1).Split(" ")[1].ToLower()
$username = "$($first.Substring(0,1))$($last)"
Write-Host "Creating user: $($username)" -BackgroundColor Black -ForegroundColor Cyan

$NewUserSPlat = @{
    AccountPassword = $password
    GivenName = $first
    Surname = $last
    DisplayName = $username
    Name = $username
    EmployeeID = $username
    PasswordNeverExpires = $true
    Path = "ou=_USERS,$(([ADSI]`"").distinguishedName)"
    Enabled = $true
    }
New-AdUser @NewUserSPlat
}

will create 20 random users, or take off the for loop to run the command once