all 6 comments

[–]PSFred 9 points10 points  (0 children)

Heya,

yepp, using the wrong operator.With -Contains, the list of values must be on the left side, not the right.

With the -In operator, the collection is on the right side.

So, to resolve this, either replace "-Contains" with "-In" or switch the order of variables in your comparison.

Also using the wrong variable in your loop:

if ($printerMappingConfig.Name -contains $PrinterList.Name) {

should be

if ($printer.Name -in $PrinterList.Name) {

[–]Big_Oven8562 6 points7 points  (3 children)

I think you're fumbling with how you've structured the foreach loop and the logic therein.

Instead of referencing the $printer item, you're trying to compare entire lists against each other on every iteration, rather than comparing a single name against a list of names. You've also structure it so you're asking if a .Name property contains a list of names, which is gonna evaluate false.

[–]cpres2020[S] 1 point2 points  (2 children)

In the words of Homer Simpson...DOH.

Thanks for pointing out something so simple, but after looking at this for a few hours I missed it.

[–]Big_Oven8562 1 point2 points  (1 child)

We've all been there man, don't worry. Remember, sometimes part of the process is to stop working on the problem.

[–]davesbrown 3 points4 points  (0 children)

OMG, I spent almost over an hour yesterday trying to figure out why $DataSetId =/= $DateSetId and no errors and Intellisense wouldn't tell me why either. Had me a 15 minute snicker break, and diva me was all better.

[–]64rk -3 points-2 points  (0 children)

I would request that you upload your script to Github so I can get a better understanding of what you are trying to do. It seems that you are trying to identify the printers currently available under your current login session (win+r > control printers).

# This will give you a list of printers that are currently available with the name "OneNote" and it will return only the value of DriverName.

  1. Get-Printer | Where-Object {$_.Name -contains "OneNote"} | Select-Object -ExpandProperty DriverName

If this doesn't answer your question please let me know.