azure - 存储帐户中的公共(public)容器

标签 azure powershell azure-storage

第一篇文章。我的 Powershell 知识不太丰富。我试图列出“PublicAccess”属性设置为“开”的所有容器。我正在尝试使用MS提供的脚本。

$rgName = "<Resource Group name>"
$accountName = "<Storage Account Name>"

$storageAccount = Get-AzStorageAccount -ResourceGroupName $rgName -Name $accountName
$ctx = $storageAccount.Context

Get-AzStorageContainer -Context $ctx | Select Name, PublicAccess

但是我需要在大量存储帐户上执行此操作。过去我曾使用“foreach($item in $list)”将内容传递到一个小脚本中。但绝不适用于多个列表。有人可以帮忙吗?

最佳答案

根据评论中您的扩展要求,这应该可行。 (我没有对其进行测试,也没有处理任何与权限或其他相关的潜在错误)

# Create a collection for the items found.
$StorageAccounts = [System.Collections.Generic.List[System.Object]] @{}

# Loop through the available Azure contexts.
foreach ($Context in (Get-AzContext -ListAvailable)) {
    # Set each subscription in turn, voiding the output.
    [System.Void](Set-AzContext -Context $Context)
    
    # Create an object with the container name, public access values and the name of the storage account/subscription.
    $StorageAccountInfo = Get-AZStorageAccount | Get-AzStorageContainer | Select-Object Name, PublicAccess, @{l = "StorageAccountName"; e = { $_.Context.StorageAccountName } }, @{l = "Subscription"; e = { $Context.Subscription.Name } }

    # If there is data found, add it to the collection.
    if ($null -ne $StorageAccountInfo) {
        $StorageAccounts.AddRange($StorageAccountInfo)
    }
}

# Export the collected information to Csv.
$StorageAccounts | Export-Csv -Path .\myStorageAccounts.csv -NoClobber -Encoding utf8

关于azure - 存储帐户中的公共(public)容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73220913/

相关文章:

c# - 使用 C# 从数据集中更新 Sql 表

sql-server - 来自 Powershell 的 Powershell DBCC CheckDB

azure - 是否可以在 Azure 存储 blob 或容器上设置持久权限?

azure - 我可以使用 Azure Blob 存储向我发送调整大小的 Blob 吗?

java - 如何在Azure的Spring云功能中设置响应状态

azure - 当文档说不需要时,Microsoft.IdentityModel.Clients.ActiveDirectory AcquireTokenAsync 始终需要资源

powershell - 将 Azure 应用服务与应用服务环境集成

powershell - PowerShell 中 [Char[]] 的用途

powershell - 使用 powershell 将整数存储在自定义对象中

c# - 是否可以在一定天数后删除特定的 blob? Azure Blob 存储