用來尋找儲存體帳戶註冊所在之復原服務保存庫的 PowerShell 指令碼
此指令碼可協助您尋找儲存體帳戶註冊所在的復原服務保存庫。
範例指令碼
Param(
[Parameter(Mandatory=$True)][System.String] $ResourceGroupName,
[Parameter(Mandatory=$True)][System.String] $StorageAccountName,
[Parameter(Mandatory=$True)][System.String] $SubscriptionId
)
Connect-AzAccount
Select-AzSubscription -Subscription $SubscriptionId
$vaults = Get-AzRecoveryServicesVault
$found = $false
foreach($vault in $vaults)
{
Write-Verbose "Checking vault: $($vault.Id)" -Verbose
$containers = Get-AzRecoveryServicesBackupContainer -ContainerType AzureStorage -FriendlyName $StorageAccountName -ResourceGroupName $ResourceGroupName -VaultId $vault.Id -Status Registered
if($containers -ne $null)
{
$found = $True
Write-Information "Found Storage account $StorageAccountName registered in vault: $($vault.Id)" -InformationAction Continue
break;
}
}
if(!$found)
{
Write-Information "Storage account: $StorageAccountName is not registered in any vault of this subscription" -InformationAction Continue
}
如何執行腳本
使用您選擇的名稱,將上述指令碼儲存在您的電腦上。 在此範例中,我們將其儲存為 FindRegisteredStorageAccount.ps1。
提供下列參數以執行指令碼︰
- -ResourceGroupName - 儲存體帳戶的資源群組
- -StorageAccountName - 儲存體帳戶名稱
- -SubscriptionID - 儲存體帳戶所屬訂用帳戶的識別碼。
下列範例會嘗試尋找 afsaccount 儲存體帳戶註冊所在的復原服務保存庫:
.\FindRegisteredStorageAccount.ps1 -ResourceGroupName AzureFiles -StorageAccountName afsaccount -SubscriptionId aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e
輸出
輸出會顯示該儲存體帳戶註冊所在之復原服務保存庫的完整路徑。 以下是範例輸出:
Found Storage account afsaccount registered in vault: /subscriptions/ aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/azurefiles/providers/Microsoft.RecoveryServices/vaults/azurefilesvault123