Database sizes

Richard Siddaway's Blog

After PowerShell one of my favourite Microsoft technologies is SQL Server. I have been working with it since version 6.5 and each new version only gets better. The introduction of SMO with SQL Server 2005 allows me to combine the two. This script will interrogate a SQL Server instance and retrieve information on the amount of space used by the databases. This could be used for growth trending as well as general monitoring of the databases.

## get-sqlinfo

## This uses the SMO assemblies to retrieve database size information

##

## Richard Siddaway June 2006

## load SMO assemblies

## use $null to prevent display of assembly load information

$null = [reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.ConnectionInfo”)

$null = [reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.SmoEnum”)

$null = [reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”)

 

clear-host

 

## set SMO variable

$Server = new-object Microsoft.SqlServer.Management.Smo.Server(“SQL1”)

 

## get the database information

 

” {0,20} {1,15} {2,15} {3,15} {4,15}” -f “Name”, “Size”, “Available”, “Log size”, “Log Used”

View original post 139 more words

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s