March 25, 2010
I have this script:
It checks for the text pattern Failure in files dated today or yesterday in a specific catalog.
I get the ouput:
Directory: X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2010-03-25 12:25 1527 NECert02SuSE_20100325_232528.txt
-a--- 2010-03-25 12:23 792 ResourcePool_resgroup-726_20100325_230002.txt
-a--- 2010-03-25 12:26 8880 testfcswin_20100325_134707.txt
IgnoreCase : True
LineNumber : 13
Line : Logon failure: unknown user name or bad password.
Filename : NECert02SuSE_20100325_232528 - Kopia.txt
Path : X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\NECert02SuSE_20100325_232528 - Kopia.txt
Pattern : Failure
Context :
Matches : {failure}
IgnoreCase : True
LineNumber : 19
Line : Error: Logon failure: unknown user name or bad password.
Filename : NECert02SuSE_20100325_232528 - Kopia.txt
Path : X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\NECert02SuSE_20100325_232528 - Kopia.txt
Pattern : Failure
Context :
Matches : {failure}
IgnoreCase : True
LineNumber : 22
Line : Error In Backup Operations! Error: An error occurred during backup operations. Logon failure: unknown user name or bad password.
Filename : NECert02SuSE_20100325_232528 - Kopia.txt
Path : X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\NECert02SuSE_20100325_232528 - Kopia.txt
Pattern : Failure
Context :
Matches : {failure}
If I only want the filename and the Line with error in it in the output. How do I do it??
001 002 003 004 005 006 007 008 | function isWithin([int]$days, [datetime]$Date) {[DateTime]::Now.AddDays($days).Date -le $Date.Date} $list = get-childitem "X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\" -recurse | where {!$_.PSIsContainer} | where {isWithin -1 $_.lastwritetime} $list foreach ($file in $list) {$file | Select-String -pattern "Failure" } |
It checks for the text pattern Failure in files dated today or yesterday in a specific catalog.
I get the ouput:
Directory: X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2010-03-25 12:25 1527 NECert02SuSE_20100325_232528.txt
-a--- 2010-03-25 12:23 792 ResourcePool_resgroup-726_20100325_230002.txt
-a--- 2010-03-25 12:26 8880 testfcswin_20100325_134707.txt
IgnoreCase : True
LineNumber : 13
Line : Logon failure: unknown user name or bad password.
Filename : NECert02SuSE_20100325_232528 - Kopia.txt
Path : X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\NECert02SuSE_20100325_232528 - Kopia.txt
Pattern : Failure
Context :
Matches : {failure}
IgnoreCase : True
LineNumber : 19
Line : Error: Logon failure: unknown user name or bad password.
Filename : NECert02SuSE_20100325_232528 - Kopia.txt
Path : X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\NECert02SuSE_20100325_232528 - Kopia.txt
Pattern : Failure
Context :
Matches : {failure}
IgnoreCase : True
LineNumber : 22
Line : Error In Backup Operations! Error: An error occurred during backup operations. Logon failure: unknown user name or bad password.
Filename : NECert02SuSE_20100325_232528 - Kopia.txt
Path : X:\Program Files\vizioncore\esxRanger Professional\Logs\Backup\NECert02SuSE_20100325_232528 - Kopia.txt
Pattern : Failure
Context :
Matches : {failure}
If I only want the filename and the Line with error in it in the output. How do I do it??
Etiketter:
powershell
Subscribe to:
Post Comments (Atom)
Blog Archive
Tags
Links
About Me
- Catherina
- I took the PowerShell Master Class for Thomas Lee in Stockholm in march 2010.
1 kommentarer:
I got help to solv this. Thx! Final script will be published soon.
Post a Comment