Here’s a little something for the sysadmin that monitors SQL servers (who doesn’t?). This handy little function retrieves SQL log messages for a specified instance. You can also specify how many of the most recent messages to retrieve.

function Get-SQLLog
{
param([string]$Instance, [Int]$SizeLimit = 10)
If ($Instance -eq $null){Write-Warning “Syntax: Get-SQLLog [-Instance] [[-SizeLimit] ]”}
Else
{
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.Smo’) | Out-Null
$Sql = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) $Instance
$sql.ReadErrorLog() | select -last $SizeLimit
}
}

»crosslinked«

No related posts.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 PeetersOnline Suffusion theme by Sayontan Sinha