使用 PowerShell 获取 Azure 文件共享大小
Get Azure File share size using PowerShell
有没有办法使用 powershell 获取 Azure 文件共享的大小?
我可以使用 Get-AzStorageShare 提取 etag、配额、层级等,但我似乎找不到从哪里获得“使用”。
我可以在门户中看到它,所以它一定来自某个地方...
从 Azure PowerShell 7.5 版开始,Az.Storage
模块中没有可直接为您提供此信息的 Cmdlet。
但是,有一个解决方法。
我们的想法是调用 Get-AzStorageShare
,这将为您提供一个 AzureStorageFileShare
. This object has a property called ShareClient
which is available in Azure Storage File SDK. Once you have access to this object, you can call GetStatistics
类型的对象方法来获取共享使用情况。
$accountName = "your storage account name"
$accountKey = "your storage account key"
$shareName = "your share name"
$ctx = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
$share = Get-AzStorageShare -Name $shareName
$client = $share.ShareClient
# We now have access to Azure Storage SDK and we can call any method available in the SDK.
# Get statistics of the share
$stats = $client.GetStatistics()
$shareUsageInBytes = $stats.Value.ShareUsageInBytes
Write-Host $shareUsageInBytes
有没有办法使用 powershell 获取 Azure 文件共享的大小?
我可以使用 Get-AzStorageShare 提取 etag、配额、层级等,但我似乎找不到从哪里获得“使用”。
我可以在门户中看到它,所以它一定来自某个地方...
从 Azure PowerShell 7.5 版开始,Az.Storage
模块中没有可直接为您提供此信息的 Cmdlet。
但是,有一个解决方法。
我们的想法是调用 Get-AzStorageShare
,这将为您提供一个 AzureStorageFileShare
. This object has a property called ShareClient
which is available in Azure Storage File SDK. Once you have access to this object, you can call GetStatistics
类型的对象方法来获取共享使用情况。
$accountName = "your storage account name"
$accountKey = "your storage account key"
$shareName = "your share name"
$ctx = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
$share = Get-AzStorageShare -Name $shareName
$client = $share.ShareClient
# We now have access to Azure Storage SDK and we can call any method available in the SDK.
# Get statistics of the share
$stats = $client.GetStatistics()
$shareUsageInBytes = $stats.Value.ShareUsageInBytes
Write-Host $shareUsageInBytes