Forum Discussion

Jamal1245's avatar
Jamal1245
Copper Contributor
Jun 04, 2020

get-printer results

Hello,

I have below code to get printers list printer port = xxx.xxx.xxx.xxx

 

 

$ports1 = Get-Printer -ComputerName $pcname1 | Select-Object -Property name | Where-Object portname -like $txtOld
foreach  ($item in $ports1) {

do something
}

 

 

When I run this; $ports1 doesn't have any value in it. So, when the execution process hits for each command $ports1 is showing empty and not doing anything. 

 

in the terminal when I run this command with the return value. it works fine and shows me a list of printers

any idea?

1 Reply

  • Jamal1245's avatar
    Jamal1245
    Copper Contributor

    I changed the code to this and worked

    $ports1 = Get-Printer -ComputerName $pcname1 | Select-Object -Property portname | Where-Object portname -like $OldIP
    $ports1 | ForEach-Object{  #($item in $ports1) {}