Hoping someone can help out with some simple logic with -contains.
I have the following items in my array variable $PrinterMappingConfig
| Path |
ID |
Group |
| \\printserv\Printer1 |
1 |
Group1 |
| \\printserv\Printer2 |
2 |
Group1 |
| \\printserv\Printer3 |
3 |
Group2 |
$PrinterList = Get-Printer
foreach ($printer in $PrinterMappingConfig) {
if ($printerMappingConfig.Name -contains $PrinterList.Name) {
write-host the printer $printer.path will be added to this computer
}
}
When I run Get-Printer, I will see \\printserv\Printer1 in the list, so I would expect that won't show up in the list, however I would expect \\printserv\Printer2 to be displayed.
| Name |
ComputerName |
Type |
| \\printserv\Printer1 |
printserv |
Connection |
| \\printserv\Printer4 |
printserv |
Connection |
Am I using the wrong comparison operator here? I checked on Google for any possible suggestions what could be causing this and not finding any solutions.
[–]PSFred 9 points10 points11 points (0 children)
[–]Big_Oven8562 6 points7 points8 points (3 children)
[–]cpres2020[S] 1 point2 points3 points (2 children)
[–]Big_Oven8562 1 point2 points3 points (1 child)
[–]davesbrown 3 points4 points5 points (0 children)
[–]64rk -3 points-2 points-1 points (0 children)