我有下面的脚本,循环通过Azure存储帐户,并从中获得一些属性。
# Connect to Azure
Connect-AzAccount
# Get all Azure subscriptions
$subscriptions = Get-AzSubscription
# Variables to store access levels and errors
$publicAccessOn = @()
$errorsaccessing = @()
# Loop through each subscription
foreach ($subscription in $subscriptions) {
Write-Output "Subscription: $($subscription.Name)"
# Select the current subscription
Select-AzSubscription -SubscriptionId $subscription.Id
# Get a list of storage accounts
$storageAccounts = Get-AzStorageAccount
# Loop through each storage account
foreach ($storageAccount in $storageAccounts) {
$storageAccountName = $storageAccount.StorageAccountName
$storageAccountRG = $storageAccount.ResourceGroupName
try {
# Get a list of containers in the storage account
$containers = Get-AzStorageContainer -Context $storageAccount.Context -ServerTimeoutPerRequest 30 | Select Name, PublicAccess
# Check if there are containers in the storage account
if ($containers -eq $null) {
Write-Host "No containers found in storage account $storageAccountName. Skipping." -ForegroundColor Cyan
continue
}
# Display the public access setting
if ($containers.PublicAccess -eq "Off") {
Write-Host "Container count is: $($containers.Count) in $storageAccountName"
Write-Host "PublicAccess Settings is Off in all container in storage account: $storageAccountName" -ForegroundColor Green
}
else
{
Write-Host "Container count is: $($containers.Count) in $storageAccountName"
Write-Host "PublicAccess Settings is ON in one or more container in storage account: $storageAccountName" -ForegroundColor Red
$publicAccessOn += $storageAccountName
}
}
catch {
# Handle any errors and log them
$errorsaccessing += $storageAccountName
}
}
# Output access levels
#$publicAccessOn
# Output errors
#$errors
}
有时检查存储帐户是它的容器失败,我已经创建了Try
循环。目前,如果我没有访问存储帐户或检查超时,它仍然在循环中向前移动,即使我不想它。任何线索什么改变或添加,因为我有点卡住目前。
以下是扫描过程中可能出现的两条错误消息。
1条答案
按热度按时间zour9fqk1#
最初,我在我的环境中遇到了同样的错误。
**错误:**x1c 0d1x
上述错误“此存储帐户不允许基于密钥的身份验证”表示您在环境中无法访问密钥身份验证。
要解决此问题,您可以执行以下步骤:
如果禁用,则更改为启用状态,如下所示:
入口:
现在我在我的环境中运行相同的脚本,并获得了具有公共访问类型的容器计数。
入口:
参考:
I'm getting Error Message: Key based authentication is not permitted on this storage account. - Microsoft Q&A由Sumarigo-MSFT提供。