Advertisement
opexxx

search.ps1

Jan 5th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $searchpattern =  "Error I want to search in log file"
  2.  
  3. $Servers = @("MYWEBAPP42","MYWEBAPP43","MYWEBAPP60","MYWEBAPP61")
  4.  
  5.  
  6. foreach ($server in $servers)
  7. {
  8.     $mypath = "\\" + $server + "\M$\SQLDBA\MyToolPath\LogFolder"
  9.      
  10.  
  11.  
  12.     $myfiles=Get-ChildItem $mypath | where {($_.CreationTime -ge $(Get-Date).AddHours(-120))}
  13.  
  14.     foreach ($file in $myfiles)
  15.     {
  16.          IF ( Get-Content $file.FullName | Select-String -Pattern  $searchpattern )
  17.         {
  18.             Write-Host $file.FullName
  19.        }
  20.     }
  21. }
  22.  
  23. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement