如何使PowerShell能够使用命令“ Get-TotalDatabaseSizeKb”? [关闭]

问题描述 投票:-1回答:1

我尝试执行命令,但抛出错误,如下所示。请帮助我安装该模块

“请单击此链接以获取错误屏幕截图”

powershell azure-sql-database azure-automation azure-sql-server
1个回答
0
投票

您需要使用Azure Metrics连接到Connect-AzureRmAccount

然后您需要创建此功能:

function Get-TotalDatabaseSizeKb
{
param($Resource)
$Result = $Resource | Get-AzureRmMetric -MetricName 'storage' -WarningAction SilentlyContinue
$DBSize = $Result.Data[$Result.Data.Count-2].Maximum
$DBSize / 1024
}

并像这样使用它:

#Size of all databases
$Databases = Get-AzureRmResource -ResourceGroupName "GROUPNAME" -ResourceType Microsoft.Sql/servers/databases
foreach ($DB in $Databases)
{
$DBSize = Get-TotalDatabaseSizeKb $DB
"DB ($($DB.Name)) $($DBSize)Kb or $($DBSize / 1024)Mb"
}
© www.soinside.com 2019 - 2024. All rights reserved.