# Output multiple values from string

**URL:** <https://forums.powershell.org/t/output-multiple-values-from-string/21009>\
**Category:** PowerShell Help\
**Created:** [November 25, 2022, 1:37pm UTC](https://forums.powershell.org/t/output-multiple-values-from-string/21009 "2022-11-25T13:37:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MindaugasRam](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mindaugasram/32/4113_2.png) [@MindaugasRam](https://forums.powershell.org/u/MindaugasRam)\
**Post date:** [November 25, 2022, 1:37pm UTC](https://forums.powershell.org/t/output-multiple-values-from-string/21009/1 "2022-11-25T13:37:57Z")

</div>

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](https://catalog.update.microsoft.com/v7/site/Search.aspx?q=KB5019966); SubType=Security Update}  
Windows Server 2019 CVE-2022-37966 @{ID=5019966; URL=[Microsoft Update Catalog](https://catalog.update.microsoft.com/v7/site/Search.aspx?q=KB5019966); 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 🙂

---

<div class="post-metadata">

**Author:** ![Matt](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Matt](https://forums.powershell.org/u/Matt)\
**Post date:** [November 25, 2022, 7:48pm UTC](https://forums.powershell.org/t/output-multiple-values-from-string/21009/2 "2022-11-25T19:48:14Z")

</div>

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.

```auto
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

```auto
 $_.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](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1)

Here is some Operator Precedence documentation, again select for the version of PS you are using  
[about Operator Precedence - PowerShell | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operator_precedence?view=powershell-5.1)

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](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_foreach?view=powershell-5.1)

Here is documentation for getting contents of a text file  
[Get-Content (Microsoft.PowerShell.Management) - PowerShell | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-5.1)

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.

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

```

---

<div class="post-metadata">

**Author:** ![MindaugasRam](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mindaugasram/32/4113_2.png) [@MindaugasRam](https://forums.powershell.org/u/MindaugasRam)\
**Post date:** [November 28, 2022, 8:56am UTC](https://forums.powershell.org/t/output-multiple-values-from-string/21009/3 "2022-11-28T08:56:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 28, 2022, 9:01am UTC](https://forums.powershell.org/t/output-multiple-values-from-string/21009/4 "2022-11-28T09:01:28Z")

</div>

Mindaugas,  
Welcome to the forum. 👋🏽

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](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) \<---- Click 👆🏽 😉

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/output-multiple-values-from-string/21009/5 "2024-05-16T20:16:16Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


