Jun 04 2020 09:55 AM
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?
Jun 04 2020 10:04 AM
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) {}