none
How to extract just the name of print driver RRS feed

  • Question

  • I am trying to populate a ComboBox with the name of installed print drivers on a server. 

    Current code:

    $printDriver = Get-WmiObject -Class Win32_PrinterDriver -ComputerName HappyServer -Credential $credential 

     Foreach($driver in $printDriver)

            { Combo1.Items.Add($driver)}

    I get the driver name but I also get extra data. how can I filter what is going in to the ComboBox ?

    Current :

     HP Color LaserJet 3800,3,Windows NT x86

    Preferred 

     HP Color LaserJet 3800

    Sunday, September 16, 2018 5:36 PM

Answers

  • David,

    Your $driver variable should contain an array.

    So you will need to select the property that hold what you are looking for.

    I believe in your case should be: $driver.Name

    Cheers,

    Sok.

    • Marked as answer by DavidTippit Monday, September 17, 2018 12:28 AM
    Sunday, September 16, 2018 6:48 PM
  • A little but tricky with names.

        $printDriver = Get-WmiObject -Class Win32_PrinterDriver -ComputerName HappyServer -Credential $credential 
        $names = $printDriver.Name |%{($_ -split ',')[0]}
        $combobox1.Items.AddRange($names)
    
    
    


    \_(ツ)_/

    • Marked as answer by DavidTippit Monday, September 17, 2018 12:28 AM
    Sunday, September 16, 2018 7:41 PM

All replies

  • David,

    Your $driver variable should contain an array.

    So you will need to select the property that hold what you are looking for.

    I believe in your case should be: $driver.Name

    Cheers,

    Sok.

    • Marked as answer by DavidTippit Monday, September 17, 2018 12:28 AM
    Sunday, September 16, 2018 6:48 PM
  • A little but tricky with names.

        $printDriver = Get-WmiObject -Class Win32_PrinterDriver -ComputerName HappyServer -Credential $credential 
        $names = $printDriver.Name |%{($_ -split ',')[0]}
        $combobox1.Items.AddRange($names)
    
    
    


    \_(ツ)_/

    • Marked as answer by DavidTippit Monday, September 17, 2018 12:28 AM
    Sunday, September 16, 2018 7:41 PM
  • This actually did exactly what I needed thank you
    Monday, September 17, 2018 12:43 AM
  • That got me one step closer but it did not remove the extraneous data 
    Monday, September 17, 2018 12:44 AM