Out-gridview to variable issue

So I’m trying to do something i thought was simple here. Grab a csv file taht just has a single column labedl ‘ComputerName’ and then allow a admin to select the computers and pipe that to a variable. Finally i just want to spit out the list the admin just selected and ask tehm to verify that is what the selected. The first iteration of the code below will show nothing in the console. If you select N and redo the selection it will then correctly display the $computer list…What am i missing?

$Accepted -eq "N"
 Write-Host "Select Computers" 
 $Computers = Import-Csv C:\Computers.csv | Out-GridView -PassThru -Title "Select the Computers to work with"
$Accepted = Read-Host "Is the list valid? (Y or N):"
Until ($Accepted -eq "Y")

Welcome back to the forum. :wave:t4:

A valid CSV file has headers. Assumed your CSV file has a header ComputerName something like this should work:

$ComputerInputList = Import-Csv -Path C:\Computers.csv

$Accepted -eq 'N'
Do {
    Write-Host 'Select Computers ...'
    $SelectedComputers = $ComputerInputList | Out-GridView -Title 'Select the Computers to work with' -OutputMode Multiple
    Write-Host "Selected computers ... `n"
    $SelectedComputers.ComputerName -join ', '
    $Accepted = Read-Host "`nIs the list valid? (Y or N) "
Until ($Accepted -eq 'Y')

If your CSV does not have a header you can provide one with the Import-Csv parameter -Header. :wink:

Thanks Olaf! This one was just driving me nuts. I appreciate the pointers. I do have a header in the file. Would you expand on why calling $computers like I did wouldn’t work on the first iteration? You go me past my issue but I still don’t understand the ‘why’ of it. Either way, thanks again!