gpt4 book ai didi

azure - 使用 PowerShell 获取 Azure 文件共享大小

转载 作者:行者123 更新时间:2023-12-02 07:35:54 28 4
gpt4 key购买 nike

有没有办法使用 powershell 获取 Azure 文件共享的大小?

我可以使用 Get-AzStorageShare 来提取 etag、配额、层等,但我似乎找不到在哪里获取“使用情况”。

我可以在门户中看到它,所以它一定来自某个地方......

enter image description here

最佳答案

从 Azure PowerShell 7.5 版本开始,Az.Storage 模块中没有 Cmdlet 可以直接向您提供此信息。

但是,有一个解决方法。

这个想法是调用 Get-AzStorageShare 这将为您提供 AzureStorageFileShare 类型的对象。 。该对象有一个名为 ShareClient 的属性Azure 存储文件 SDK 中提供了该文件。一旦您有权访问该对象,您就可以调用 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

关于azure - 使用 PowerShell 获取 Azure 文件共享大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72296928/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com