简体   繁体   中英

How do I get the initial database size in PowerShell SQLPS?

I have been searching for a few days now on how to get the initial size of a database and its logs files via PowerShell SQLPS module. For some unknown reason this information is not included in the properties of the returned object from the Get-SqlDatabase command.

Thanks for the help.

First of all, the label 'initial size' is a bit unfortunate as it is rather the actual size - see this blog article about it

That being said, you could try something like this

$db = Get-SqlDatabase YourDBName

# Size of files of primary group
$db.FileGroups['Primary'].Files |
    Select-Object -Property Name, @{N = 'Size'; E = { $_.Size / 1KB }}

# Size of log files
$db.LogFiles |
    Select-Object -Property Name, @{N = 'Size'; E = { $_.Size / 1KB }}

For a test database on my home lab this looked like this

PS> $db.FileGroups['Primary'].Files |
      Select-Object -Property Name, @{N = 'Size'; E = { $_.Size / 1KB }}

Name    Size
----    ----
AXDB   12408
AXDB_2    50

PS> $db.LogFiles |
      Select-Object -Property Name, @{N = 'Size'; E = { $_.Size / 1KB }}

Name     Size
----     ----
AXDB_log 5448

安全管理系统

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM