-1

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.

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
GKman
  • 503
  • 1
  • 5
  • 19

1 Answers1

0

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

SSMS

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
  • Hi thanks for the reply. according to your blog article you referred to, there is some sort of "initial size" (I think it is better to refer to it from now on as 'min-size') it is just stored else where, and not in the database properties. I still would like some way to grab this value with powershell. – GKman Sep 28 '16 at 12:07
  • Well then IMHO you should start another question as the property you initially requested is retrieved by the PowerShell code above - but to be honest I don't think that there is a nice & simple way to get it via a built-in PowerShell cmdlet as you even have to use a `DBCC` command to grab the info out of the page header. However, maybe someone else had the needs to get it too and built something for it so maybe you are lucky and get a solution :) – DAXaholic Sep 28 '16 at 12:16