azure - 使用 powershell 检查 Azure 存储帐户文件共享已用容量的快速方法

标签 azure powershell

通过存储资源管理器检查存储帐户文件共享文件夹的文件数量和容量太慢。 有没有更快速的方法来获取这些信息?例如,通过 powershell?

最佳答案

请使用以下代码(在PowerShell ISE中编写):

$fileinfor =@{count=0;length=0}

function file_info()
{

$context = New-AzStorageContext -StorageAccountName your_storage_account_name -StorageAccountKey your_storage_account_key
$shares = Get-AzStorageShare -Context $context

foreach($share in $shares)
{
#get all the files and directories in a file share
$filesAndDirs = Get-AzStorageFile -ShareName $share.name -Context $context

foreach($f in $filesAndDirs)
{
if($f.gettype().name -eq "CloudFile")
{
Write-Output $f.name
$fileinfor["count"]++
$fileinfor["length"]=$fileinfor["length"]+$f.Properties.Length

}
elseif($f.gettype().name -eq "CloudFileDirectory")
{
list_subdir($f)
}
}

}
Write-Output ""
Write-Output "File total count: "$fileinfor["count"]
Write-Output "File total length: "$fileinfor["length"]

}


function list_subdir([Microsoft.WindowsAzure.Storage.File.CloudFileDirectory]$dirs)
{

$path = $dirs.Uri.PathAndQuery.Remove(0,($dirs.Uri.PathAndQuery.IndexOf('/',1)+1))
$filesAndDirs = Get-AzStorageFile -ShareName $dirs.share.name -Path $path -Context $context | Get-AzStorageFile
foreach($f in $filesAndDirs)
{
if($f.gettype().name -eq "CloudFile")
{
Write-Output $f.name
$fileinfor["count"]++
$fileinfor["length"]=$fileinfor["length"]+$f.Properties.Length

}
elseif($f.gettype().name -eq "CloudFileDirectory")
{
list_subdir($f)
}

}

}



file_info

测试结果:

enter image description here

关于azure - 使用 powershell 检查 Azure 存储帐户文件共享已用容量的快速方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55728404/

相关文章:

powershell - 从远程脚本 block 调用函数

azure - 尝试以非 root 用户身份运行时 AKS crashloopbackoff

c# - 如何将 www.example.com 重定向到 example.com?

azure - 触发计时器从powershell触发Azure功能

PowerShell Get-ChildItem 并跳过

powershell - 使用PowerShell将日志行从起始字符串提取到第一个时间戳

powershell - 强制以管理员身份运行 PowerShell 脚本

azure - 使用自托管 Azure Service Fabric 调用 Web API 时出错

database - Azure SQL 数据库会自动升级到新的服务级别吗?

python - 动态创建自适应卡片机器人框架azure