我正在编写一个PowerShell脚本,它会将我的孤儿vhds
列表放入azure中,但如果我没有存储帐户的访问权限,那么我就会遇到问题。
除非锁定任何存储帐户,否则此方法无效。
Login-AzureRmAccount
$SA = Get-AzureRmStorageAccount
$UMD = $SA | Get-AzureStorageContainer | Get-AzureStorageBlob | Where {$_.Name -like '*.vhd'}
$UMVHDS = $UMD | Where {$_.ICloudBlob.Properties.LeaseStatus -eq "Unlocked"}
$MVHDS = Get-AzureRmDisk
$MVHD = $MVHDS | Where {$_.OwnerId -eq $null}
$RmDiskInfo = foreach ($UMVHD in $UMVHDS)
{
$StorageAccountName = if ($UMVHD.ICloudBlob.Parent.Uri.Host -match '([a-z0-9A-Z]*)(?=\.blob\.core\.windows\.net)') {$Matches[0]}
$StorageAccount = $SA | Where { $_.StorageAccountName -eq $StorageAccountName }
$Property = [ordered]@{
AbsoluteUri = $UMVHD.ICloudBlob.Uri.AbsoluteUri;
LeaseStatus = $UMVHD.ICloudBlob.Properties.LeaseStatus;
LeaseState = $UMVHD.ICloudBlob.Properties.LeaseState;
StorageType = $StorageAccount.Sku.Name;
StorageAccountName = $StorageAccountName;
ResourceGroupName = $StorageAccount.ResourceGroupName
}
New-Object -TypeName PSObject -Property $Property
}
$RmDiskInfo | Export-Csv -Path '.\UnusedUnmanagedVHDs.csv' -NoTypeInformation
$MVHD | Export-Csv -Path '.\UnusedManagedVHDs.csv' -NoTypeInformation
错误: 错误:Get-AzureStorageContainer:范围' / subscriptionsxxxxxx-xxxx-xxxx-bea7-31faae224077 / resourceGroups / Test-RG-BlobDeletion / provid ers / Microsoft.Storage / storageAccounts / str1test'因为以下范围被锁定,所以无法执行写操作
答案 0 :(得分:0)
要阅读,请列出您必须使用链接到该存储帐户的密钥的容器内容,例如:
$ctx = New-AzureStorageContext -StorageAccountName <name> -StorageAccountKey <key>
Get-AzureStorageContainer -Context $ctx
有关访问Blob和容器的更多信息,请访问:https://docs.microsoft.com/en-us/azure/storage/blobs/storage-manage-access-to-resources