Databases Reference
In-Depth Information
[datetime] $date,
[int] $last,
[string] $Outfile
)
$readbuffer
=
get-content -path $infile -encoding unicode |select-object -last $last
$i
=
0
[datetime] $date
[string] $outbuffer
$outbuffer
=
""
foreach($line in $readbuffer)
{
$i
++
;
$mydate
=
$line.substring(0,22)
if($line -ne "")
{
if($mydate -ge $date)
{
if ($line -like "*Error:*")
{
write-output "$i: $line"
$outbuffer
=
$outbuffer
+
$line
}
}
}
}
set-content -path $outfile -value $outbuffer
Execute the
read-errorlog2.ps1
script with the same parameters as before, and with the addition of an
output filename (see Figure 3-29):
.\read-errorlog2.ps1 "C:\Program Files\Microsoft SQL Server\MSSQL10.
MSSQLSERVER\MSSQL\Log\ERRORLOG" "2008-11-11 12:53:16.49" 10 c:\test.log
Figure 3-29
When the script is executed, it both displays the results on the screen and writes to the log file
C:\test.log
, as shown in Figure 3-30.
Search WWH ::
Custom Search