The following script examines servers from (part of) your Active Directory domain, identifies SQL servers and lists the instances with their total database sizes.
Archive for the ‘SQL’ Category
Get SQL Log Messages with Windows Powershell
Dec 4th, 08
/ 0 Comments
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
}
}
