March 25, 2010
I have this script:

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??
March 23, 2010
Today I made my first powershell script and put it in use.
It deletes files older than 30 days in a tree structure, count number of  files removed and total file size removed.


001
002
003
004
005
006
007
008
009
010
$date = [DateTime]::Now.AddDays(-30)
$list = get-childitem L:\scan\ -recurse | where {!$_.PSIsContainer} | where {$_.LastWriteTime -le $date}
$sizetotal = 0
$files =0
foreach ($file in $list)
{$sizetotal = $sizetotal + $file.Length/1MB
 $files++
 Remove-Item $file.fullname -force}
"No of files removed: " + $files
"Total file size in MB: " + "{0:N0}" -f $sizetotal
March 11, 2010
Here comes some scripts later on....