still learning powershell. I have a script that moves an xml file based on a search string but it needs to match more than 1 search string and I'm struggling with a way to do this.
Here's the code as I have it, which currently works for a single string:
$SrcDir = "c:\source"
$DestDir = "c:\destination"
$SearchString1 = "String1"
$SearchString2 = "String2"
Get-ChildItem $SrcDir -filter *.xml |
Select-String $SearchString1 -List |
Select-Object Path |
Move-Item -Dest $DestDir
So it's clear what I'm trying to achieve: If the xml file contains $SearchString1 AND $SearchString2 then move from source to destination. I can't seem to make it match both. It's probably very simple, or maybe I need to do it a different way, but I would appreciate some help.
Get-Help Select-Stringsays, this cmdlet accepts Regular Expressions. So why notSelect-String -Pattern "($SearchString1|$SearchString2)"to make it quite simple?"String(1|2)"(or similiar)