Reputation: 3
I have the following script that allows me to get user IDs on the console and then check expiration dates of relevant users' AD accounts. The part gathering the IDs is as below:
[array]$input = (Read-Host “Staff Numbers: ”).Split([System.Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries)
However when I paste the staff numbers of the user to the console, it reads only the 1st line and ends the script. The other numbers after the first are just displayed on the console after.
Any idea on what is wrong?
Upvotes: 0
Views: 101
Reputation: 5227
Read-Host
is supposed to take only one line, as per the docs:
The Read-Host cmdlet reads a line of input from the console.
If you want to get multiple lines you can either:
Read-Host
inside a loop like here
$arr = @(While($line=(Read-Host).Trim()){$line})
$userInput = read-host "Enter a list of comma separated hostnames"
$data = $userInput.split(",").trim(" ")
Upvotes: 1