This maybe helps some people which need to copy mutiple files. In my example I search for Contoso in files called info_*****.txt I need to copy them and also copy the file data_*****.txt.
$sourceFolder = "E:\temp\source" $destinationFolder = "E:\temp\folder1" $files = Get-ChildItem $sourceFolder -Filter *.txt -Recurse | Select-String "Contoso" # Get all Files with Contoso Write-Host "Files found: " $files.count # Number of files found foreach ($file in $files){ Get-Childitem $sourceFolder | Where-Object { $_.name -eq $file.filename } | Copy-Item -Destination $destinationFolder # copy all info_*****.txt files $name = $file.filename -replace "info_", "data_" Get-Childitem $sourceFolder | Where-Object { $_.name -eq $name } | Copy-Item -Destination $destinationFolder # copy all data_*****.txt files }
More Infos about Select-String and file copy