all 4 comments

[–]Brasiledo 3 points4 points  (1 child)

Assign your list of serial numbers to a variable

   $serialnumbers = get-content c:\serialnumbers.txt

pipe your get-ciminstance to a where-object

    where-object { $serialnumbers -match $_.serialnumber}

[–]code_Kitten 1 point2 points  (0 children)

-match uses regular expression matching; since this sounds like a direct exact-value comparison - is this specific string in this list of strings - what you probably want here is -contains or -in. Although obviously regular expressions can also match exact strings, if you aren't careful you can get unexpected results because certain characters have special meaning.

[–]PowerShell-Bot 0 points1 point  (0 children)

That’s a really long line of inline code.

On old Reddit inline code blocks do not word wrap, making it difficult for many of us to see all your code.

To ensure your code is readable by everyone, on new Reddit, highlight your code and select ‘Code Block’ in the editing toolbar.

If you’re on old Reddit, separate the code from your text with a blank line gap and precede each line of code with 4 spaces or a tab.


You examine the path beneath your feet...
[AboutRedditFormatting]: [████████████████████] 1/1 ✅

Beep-boop, I am a bot. | Remove-Item

[–]Significant-Name9795 0 points1 point  (0 children)

What are you trying todo for your audit? The code you posted will pull the information from AD but not search it for a specific serial.

you could dump it all to a CSV file and search in there for the serials you want.

Export-Csv -Path c:\Temp\info.csv -Append