Skip to content

Instantly share code, notes, and snippets.

@martin9700
Created January 4, 2015 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin9700/f28713757122bf1cf994 to your computer and use it in GitHub Desktop.
Save martin9700/f28713757122bf1cf994 to your computer and use it in GitHub Desktop.
If ($Result)
{
$BackupByDBQuery = @"
WITH fs
AS
(
SELECT database_id, type, size * 8.0 / 1024 AS size
FROM sys.master_files
)
SELECT
db.name,
db.database_id,
CAST(ROUND((SELECT SUM(size) FROM fs WHERE type = 0 AND fs.database_id = db.database_id),2) AS DECIMAL(12,2)) AS FileSizeMB,
CAST(ROUND((SELECT SUM(size) FROM fs WHERE type = 1 AND fs.database_id = db.database_id),2) AS DECIMAL(12,2)) AS LogSizeMB
FROM sys.databases as db
WHERE name = '$($Select.Name)'
"@
$NewSizes = Invoke-SQLQuery -Instance $Instance -Database Master -MultiSubnetFailover -Query $BackupByDBQuery
$Select | Add-Member -MemberType NoteProperty -Name NewFileSizeMB -Value ($NewSizes.FileSizeMB)
$Select | Add-Member -MemberType NoteProperty -Name NewLogSizeMB -Value ($NewSizes.LogSizeMB)
Write-Output $Select
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment