Skip to content

February 12, 2013

Get VLF Counts for all Databases using Powershell

by Scott Newman

Quick script (as always) to get the vlf counts for all your databases via powershell.  Bit of a misnomer though, it just executes the sql for each database.  AFAIK, there is no mechanism in SMO to retrieve the vlf count directly.  This uses SQLPSX

param(
	[string]$serverName = "ServerName"
)
Import-Module SqlServer

$outputs = @();
$qry = @"
DBCC LOGINFO
"@

$server = Get-SqlServer -sqlserver $serverName
$dbs = Get-SqlDatabase -sqlserver $server | where{$_.IsSystemObject -ne $true}
foreach($db in $dbs)
{
	$res = Get-SqlData -dbname $db.name -sqlserver $server -qry $qry
	$output = New-Object -TypeName PSObject -Property @{
		DatabaseName = $db.Name
		VLFCount = $res.Count
	}
	$outputs += $output
}
$outputs | Format-Table -AutoSize
Read more from Powershell, SQL Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

%d bloggers like this: