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: