我为每个容器运行此脚本,删除超过35天的SQL备份。任何人都可以帮我写一个循环(foreach)来浏览每个容器,删除超过35天的文件吗?
这是我的一个容器的脚本,但我需要为每个容器运行它。
$SubScriptionName = "subname"
$StorageAccountName = "storagename"
Select-AzureSubscription –SubscriptionName $SubScriptionName
Set-AzureSubscription –SubscriptionName $SubScriptionName –CurrentStorageAccount $StorageAccountName
$Container = "nameOfContainer"
$CleanupOlderThan35Days = [DateTime]::UtcNow.AddDays(-35)
Get-AzureStorageBlob -Container $Container | Where-Object { $_.LastModified.UtcDateTime -lt $CleanupOlderThan35Days } |Remove-AzureStorageBlob
答案 0 :(得分:0)
脚本中心提供了一个Azure Runbook,可以为您执行此操作。
https://gallery.technet.microsoft.com/scriptcenter/Remove-Storage-Blobs-that-aae4b761
您可以将Azure自动化帐户作为Runbook(我的首选项)运行,也可以提取完成本地脚本实现所需的PowerShell。