Hi there,
I'm writing a script that will show a form with a list of printers that, once one is selected, goes off and creates a printer port and installs the necessary drivers.
I'm importing a csv containing a list of printer models and its host IP : HP Officejet 6100,180.
The script then gets the subnet the printer will be located on based on the machine the script is run from [all sites are /24].
I don't want the IP to be shown in the list, just the printer model, which brings me to my issue: how do I get the corresponding IP from the imported csv variable?
Here's what I've got at the moment:
$printers = import-csv .\list.csv -header printer,IP
[... bit of code to create the form ...]
ForEach ($printer in $printers) {
[void] $objListBox.Items.Add($printer.printer)}
[... code for the OK button ...]
$OKButton.Add_Click({$script:selectedPrinter = $objListBox.SelectedItem.ToString()})
This is where I'm getting stuck. Would the right track be to use $objListBox.SelectedIndex and tie this up with the index of $printers? If so, how do I go about this?
Thanks in advance for any response!
UPDATE:
Got it :
$printerIP = $printers.Get($objListBox.SelectedIndex) | Select IP
$printerIP.IP
If there is a more elegant method of doing the same, I'm all ears!