Output multiple values from string

Please help with the output. I am trying to extract multiple KB numbers from the strings and can’t get it. Please advice
For 1 kb it is working ok with:
Get-MsrcCvrfDocument -ID 2022-Nov | Get-MsrcCvrfAffectedSoftware | Select-Object FullProductName,CVE,KBArticle | Where {$.FullProductName -like “server” -and $.FullProductName -notlike “core installation” -and $_.KBArticle -like “KB5019966”}

Output as expected: FullProductName CVE KBArticle


Windows Server 2019 CVE-2022-23824 @{ID=5019966; URL=Microsoft Update Catalog; SubType=Security Update}
Windows Server 2019 CVE-2022-37966 @{ID=5019966; URL=Microsoft Update Catalog; SubType=Security Update} …

But I need to pull for all following KBs : KB5019081, KB5019966, KB5019964, KB5020023

Can’t figure out. I am very new to PowerShell, don’t judge hard :slight_smile:

You are close.

Your code as posted has a couple errors in it. Given you provided output, you probably just forgot to include the wildcards to your searches.

Get-MsrcCvrfDocument -ID 2022-Nov | Get-MsrcCvrfAffectedSoftware | Select-Object FullProductName,CVE,KBArticle | Where {$_.FullProductName -like “*server*” -and $_.FullProductName -notlike “*core installation*” -and $_.KBArticle -like “*KB5019966*”}

You are wanting to find 4 KBs. There are two options for you.

Option 1.
Since you are only looking for 4 KBs, you could just change your -and $_.KBArticle -like into a series of

 $_.KBArticle -like "*search string*  -or 

and repeat till you have all 4.

Here is the about Operators documentation. This is for PS 5.1, but you can select whatever version of PS you are using.
about Operators - PowerShell | Microsoft Learn

Here is some Operator Precedence documentation, again select for the version of PS you are using
about Operator Precedence - PowerShell | Microsoft Learn

Option 2.
Use a foreach loop. This is a bit over kill for just trying to find 4 KBs in a onetime scenario. However, if you wanted to make your script easier to reuse with a varying number of KBs, this could be one way to go. Create a simple text file with the list of KBs, put that list into a variable, then run it through a foreach loop.

Here is the documentation for using a foreach loop
about Foreach - PowerShell | Microsoft Learn

Here is documentation for getting contents of a text file
Get-Content (Microsoft.PowerShell.Management) - PowerShell | Microsoft Learn

Give the -or operator a try, but if you run into any issues, let me know. I did test this approach to double check everything, so it works. As long as you don’t forget the wild cards for your -like searches, you only need to play with the below section of your script.

-and $_.KBArticle -like “*KB5019966*”

Hello Matt,
Thanks for you reply and advice. I can confirm it works with OR. But as per option 2 suggestion, I think will go that way as need this on on a regular basis to have automation. So scenario would be pull KB required KB from DB, write to txt file and then run script for each of the number. Let me try to work on this and will let you know if any more help needed. This is how I corrected for the required KBs:

-and (
$.KBArticle -like “KB5019966” -or
$
.KBArticle -like “KB5019964” -or
$.KBArticle -like “KB5019081” -or
$
.KBArticle -like “KB5020023” -or
$.KBArticle -like “KB5020009” -or
$
.KBArticle -like “KB5020000” -or
$_.KBArticle -like “KB5020019” )

Thanks

Mindaugas,
Welcome to the forum. :wave:t4:

As you can see your code got a little messed up by the forum software. So please when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink: