Powershell – How to add mulitple user or values to an Array

powershell

I wanna create a powershell script in which I want to add multiple values to an Array (Add into Array).

eg: I have 10 users in my company and want to create their AD account (without using csv file), if I use "Read-Host" as below. Can I loop "read-host" to show 10 times and add values to an array and list as below??

$FirstName = Read-Host "Enter the first name of the employee"
$LastName = Read-Host "Enter the last name of the employee"
[INT]$empid = Read-Host "Enter the employee number"
$group = Read-Host "Enter the group name"
$homedrive = Read-Host "Enter the home drive"

$NewHire = @{}
$NewHire.Name = $FirstName
$NewHire.Empid = $empid
$NewHire.LastName = $LastName
$NewHire.homedrive = $homedrive

$Objectname = New-Object PSobject -Property $NewHire

$objectname

Output of this file would be as below,

Name  LastName Empid homedrive
----  -------- ----- ---------
phani ukkalam   3333 FDS      

Best Answer

You can add a wscript shell to prompt the user for whether to continue or not, and put it in a do while loop.

The loop condition here, is dependant on the user pressing yes to add more users:

$wsh = new-object -comobject wscript.shell

do {
    $FirstName = Read-Host "Employee name"

    #and so on, and so on, end with this:

    $answer = $wsh.popup("Do you want to add more users?", 0,"More users?",4) 
    If ($answer -eq 6) { 
            $continue = $True 
        } else { 
            $continue = $False 
        } 
} while ($continue -eq $True)