Skip to content

Instantly share code, notes, and snippets.

@TinyToons
Forked from ghotz/Get-ASDBSizes.ps1
Last active August 17, 2022 10:55
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 TinyToons/e9d6d4d5902965b0d1b034399a613a8d to your computer and use it in GitHub Desktop.
Save TinyToons/e9d6d4d5902965b0d1b034399a613a8d to your computer and use it in GitHub Desktop.
Get Analysis Services databases size
<#
.SYNOPSIS
Export Power BI Model Size
.DESCRIPTION
#>
function Export-ModelSize{
param(
[string]$OutputFolder
)
Write-Host "Exporting Model Size..."
$ServerName="SSASServer\SSASInstance"
$loadInfo = [Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$outputfile = "$OutputFolder\PBIRS_ModelSize.csv"
if (Test-Path $outputfile) {
Remove-Item $outputfile
}
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
Write-Output (“Server ‘{0}’ not found” -f $ServerName)
break
}
$sum=0
foreach ($d in $server.Databases ){
New-Object PSObject -Property @{
Name = $d.Name;
ItemID = $d.Name.SubString(0,36); # Mapping to the ItemID column from Catalog table
SizeMB = [math]::Round($d.EstimatedSize/1024/1024,2);
} | export-csv -Path $outputfile -NoTypeInformation -Append
}
}
Param($ServerName="GSRVBI1")
cls
$loadInfo = [Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
Write-Output ("Server [{0}] not found" -f $ServerName)
break
}
$sum = 0
foreach ($d in $server.Databases)
{
Write-Output ("Database: {0}; Status: {1}; Size: {2}MB" -f $d.Name, $d.State, ($d.EstimatedSize/1024/1024).ToString("#,##0"))
$sum = $sum + $d.EstimatedSize / 1024 / 1024
}
Write-Output ("Total size: {0}MB" -f $sum.ToString("#,##0"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment