O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Checking the Database Usage

Using the object retrieved in the $sql_server variable, you can create a quick report of database usage using the databases property of that object, as shown here:

PS SQLSERVER:\SQL\<servername>\<instancename>>$sql_server.databases| Format-Table -autosize Name,@{    Label= "% Used"    Expression={[math]::round((($_.spaceavailable/1kb)/$_.size),2)}  }Name               % Used----               ------AdventureWorks2012   0.27Empty_Db             0.07master               0.14model                0.22msdb                 0.01my_database          0.23tempdb               0.8

Using the Format-Table cmdlet, you can easily and quickly create all kinds of reports. Some capabilities we haven’t discussed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required