[Solved] multiple exclude rules in powershell


I post this as an answer as I don’t have the characters to do it as comment.
Let me see if I understand this.

$Files = Get-ChildItem -File C:\Setup | select Name, LastWriteTime

You then have an export of the files like:

Name                           LastWriteTime       
----                           -------------       
SS_MM_Master_Finland_2017.txt  6/27/2018 4:30:09 PM
SS_MM_Master_Finland_2018.txt  6/27/2018 4:30:09 PM
SS_MM_Master_Germany_2017.txt  6/27/2018 4:30:09 PM
SS_MM_Master_Germany_2018y.txt 6/27/2018 4:30:09 PM
SS_MM_Master_Italy_2017.txt    6/27/2018 4:30:09 PM
SS_MM_Master_Italy_2018.txt    6/27/2018 4:30:09 PM

And then you can go with an foreach with if like:

foreach ($File in $Files) {

If ($File.Name -like "*Italy*" -and $File.Name -like "*2017*") {
Write-Host $File.Name
}
Else{
Write-Host "This is not the file you are looking for" $file.Name
}
}

I believe you can understand the concept behind this code. You can replace the Italy with a variable that you can do with Read-Host that goes for all your conditions on the if statement and then if those are true move the file to the other folder.

Hope this answer will help you.

solved multiple exclude rules in powershell