您的位置:首页 > 运维架构 > Shell

get azure subscriptions‘ all stroages,containers and blobs by PowerShell

2017-11-17 10:48 316 查看
导到excel里

# Add your Azure account to the local PowerShell environment.
Add-AzureRmAccount -Environment AzureChinaCloud

$x=1

$excel = New-Object -ComObject Excel.Application

$excel.Visible = $true

$workbook = $excel.Workbooks.add()

$sheet = $workbook.worksheets.Item(1)

$SubscriptionNames = Get-AzureRMSubscription

foreach ($sub in $SubscriptionNames)
{
$subname=$sub.name

$sheet.cells.item($x, 1) = "SubscriptionName"
$x++
$sheet.cells.item($x, 1) = $subname
$x++

Select-AzureRMSubscription -SubscriptionName $subname
$StorageAccountNames=Get-AzureRmStorageAccount

foreach($str in $StorageAccountNames)
{
$strname=$str.StorageAccountName
$strrg=$str.ResourceGroupName

$sheet.cells.item($x, 2) = "ResourceGroup"
$x++
$sheet.cells.item($x, 2) = $strrg
$x++
$sheet.cells.item($x, 3) = "storage account name"
$x++
$sheet.cells.item($x, 3) = $strname
$x++

$StorageAccountKey = Get-AzurermStorageaccountKey -ResourceGroupName $strrg -Name $strname
$Ctx = New-AzureStorageContext $strname -StorageAccountKey $StorageAccountKey.GetValue(0).value
$containers=Get-AzureStorageContainer -Context $Ctx
$sheet.cells.item($x, 4) = "container"
$x++
foreach($con in $containers)
{
$conname=$con.Name
$sheet.cells.item($x, 4) = $conname
$x++
$blobs=Get-AzureStorageBlob -Context $ctx               -Container $conname

$sheet.cells.item($x, 5) = "blob"
$x++

foreach($blob in $blobs)
{
$blob2=$blob
$sheet.cells.item($x, 5) = $blob2.Name
$sheet.cells.item($x,2) = $blob2.BlobType
$x++
}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐