Paste an array into a variable

You’ve got a list of values, you want that in an array.

You could copy it to a file, and import it. You could dump it as a string and split it into an array.. or you could Create-ArrayFromPastedText.

function Create-ArrayFromPastedText ($returnvalue = "")
{
    $result = @()
    while ($true) {
        $value = read-host    
        if ($value -eq $returnvalue){
            return $result
        } else {
            $result += $value
        }
    }
}

You can use it like this

$MyArray = create-Arrayfrompastedtext
#Here is a read-host line, just copy and paste your list of computers/users etc
Item1
Item2
Item3

#when you enter an empty line the array closes and returns
#if you want your array to include empty lines use the -returnvalue paramter to change
#the value that signifies the end of the array.

#And then just use your array
$MyArray |?{$_ -match '[13]'}
Item1
Item3