Get SQL database size using Windows Powershell

The following script examines servers from (part of) your Active Directory domain, identifies SQL servers and lists the instances with their total database sizes.

Continue reading Get SQL database size using Windows Powershell

Get SQL Log Messages with Windows Powershell

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«