Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to read sql server database properties

Reply
 
Old 10-15-2008   #1 (permalink)
AdityaKir


 
 

How to read sql server database properties

hi,

I have an requirement wherein I need to report the following properties of
the database

1. The database size of the Onepoint database
2. The autogrowth Properties viz., File Growth and Maximum File Size.

Does anybody has any idea on how to go about this.

Thanks,

Aditya

My System SpecsSystem Spec
Old 10-18-2008   #2 (permalink)
RichS [MVP]


 
 

RE: How to read sql server database properties

This information is a bit scatter but we can find it like this.

This is written using SQL SERVER 2005

# 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("server-name")
$db = $server.databases


Write-Host "AdventureWorks database"
Write-Host "Database size = " $db["AdventureWorks"].Size

Write-Host "File Information"
$db["AdventureWorks"].Filegroups["PRIMARY"].Files

Load the SMO assemblies. Connect to the server object & pick off the
database you are interested in.

The size is a direct property. The autogrowth you need to look in
filegroups and then at the files. If you have more than one file group you
will need to loop throught them. The max file size in reported in KB and -1
means unlimited growth
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"AdityaKir" wrote:
Quote:

> hi,
>
> I have an requirement wherein I need to report the following properties of
> the database
>
> 1. The database size of the Onepoint database
> 2. The autogrowth Properties viz., File Growth and Maximum File Size.
>
> Does anybody has any idea on how to go about this.
>
> Thanks,
>
> Aditya
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can VBScript read foxpro 2.6 database? VB Script
How to retrieve the extended Properties of a database PowerShell
Read txt file and compare to database VB Script
How to force a database recovery + recovered properties bug Live Mail
interesting read> media player database Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46