& { $path = 'd-drive\ifsbosystem\log\*.Log*' # Where and what to look for $serverpattern = "REJK-P-APP" # server name pattern $servercount = 1..4 # server 1..n $searchpattern = '2016-02-01 09:42' # ----------- code here ------------ # $files = $servercount | ForEach-Object { Get-Item ("\\$serverpattern{0:d3}\$path" -f $_) | Where Name -match '\.log' } $strings = $files | Select-String -Pattern $searchpattern $openfiles = $strings | Out-GridView -PassThru $openfiles | Sort-Object Path -Unique | ForEach-Object { & 'C:\Program Files (x86)\Notepad++\notepad++.exe' $_.Path } }