I have a script that builds a GUI with a list of printers that will be selected by the user. These printers are also on a CSV file built like this : Computer (name of the printer); IP xxxx;x.x.x.x
I want to collect all the selected values in an array named x Then I want to take every entry in the CSV that corresponds to the selected item and put it in another array named y Finally I export the y array into a new CSV that will be used to install the printers on the domain. I tried to go straight from second step to last step but i couldn't.
Here is the part of the code :
$OKButton.Add_Click({
foreach ($objItem in $objListbox.SelectedItems)
{$x += $objItem}
y=@()
for ($i=0; $i -lt $x.length; $i++)
{
$y[$i]=Import-Csv C:\Users\Administrateur\Desktop\Classeur33.csv | Where-Object {$_.Computer -eq $x[$i]}
}
$y > C:\Users\Administrateur\Desktop\allezjoue.csv
I've tried to do it with a 3 values x array in another script and it worked fine, but I really need to keep the listbox that allows the user to select the printers he wants.
Powershell always returns me "Index out of range" I tried to put "$y=$x" so they have the same range, but when I do this it returns that I can't index in an object which has "System.string" type.