Get VLF Counts for all Databases using Powershell

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

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

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

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

Leave a Reply

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

You are commenting using your 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.