Skip to content

Commit e0027fc

Browse files
authored
Merge pull request #102492 from dcurwin/ps-afs
Find Recovery Services Vault script
2 parents 952593b + e6b42dd commit e0027fc

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

articles/backup/powershell-backup-samples.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ ms.custom: mvc
99

1010
The following table links to PowerShell script samples that use Azure Backup to back up and restore data.
1111

12-
| | |
12+
| | |
1313
|---|---|
14-
|**Back up virtual machines**||
1514
| [Back up an encrypted virtual machine to Azure](./scripts/backup-powershell-sample-backup-encrypted-vm.md) | Back up all data on the encrypted virtual machine.|
16-
| | |
15+
| [Find Registered Storage Account](./scripts/backup-powershell-script-find-recovery-services-vault.md) | Find the recovery services vault where the storage account is registered |
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: PowerShell Script - find Vault for Storage Account
3+
description: Learn how to use an Azure PowerShell script to find the recovery services vault where your storage account is registered.
4+
ms.topic: sample
5+
ms.date: 1/28/2020
6+
---
7+
8+
# Powershell Script to find the Recovery Services Vault where a Storage Account is registered
9+
10+
This script helps you to find the recovery services vault where your storage account is registered.
11+
12+
## Sample script
13+
14+
```powershell
15+
Param(
16+
[Parameter(Mandatory=$True)][System.String] $ResourceGroupName,
17+
[Parameter(Mandatory=$True)][System.String] $StorageAccountName,
18+
[Parameter(Mandatory=$True)][System.String] $SubscriptionId
19+
)
20+
21+
Connect-AzAccount
22+
Select-AzSubscription -Subscription $SubscriptionId
23+
$vaults = Get-AzRecoveryServicesVault
24+
$found = $false
25+
foreach($vault in $vaults)
26+
{
27+
Write-Verbose "Checking vault: $($vault.Id)" -Verbose
28+
29+
$containers = Get-AzRecoveryServicesBackupContainer -ContainerType AzureStorage -FriendlyName $StorageAccountName -ResourceGroupName $ResourceGroupName -VaultId $vault.Id -Status Registered
30+
31+
if($containers -ne $null)
32+
{
33+
$found = $True
34+
Write-Information "Found Storage account $StorageAccountName registered in vault: $($vault.Id)" -InformationAction Continue
35+
break;
36+
}
37+
}
38+
39+
if(!$found)
40+
{
41+
Write-Information "Storage account: $StorageAccountName is not registered in any vault of this subscription" -InformationAction Continue
42+
}
43+
```
44+
45+
## How to execute the script
46+
47+
1. Save the script above on your machine with a name of your choice. In this example, we saved it as *FindRegisteredStorageAccount.ps1*.
48+
2. Execute the script by providing the following parameters:
49+
50+
* **-ResourceGroupName** - Resource Group of the storage account
51+
* **-StorageAccountName** - Storage Account Name
52+
* **-SubscriptionID** - The ID of subscription where the storage account is present.
53+
54+
The following example tries to find the recovery services vault where the *afsaccount* storage account is registered:
55+
56+
```powershell
57+
.\FindRegisteredStorageAccount.ps1 -ResourceGroupName AzureFiles -StorageAccountName afsaccount -SubscriptionId ef4ad5a7-c2c0-4304-af80-af49f49af3d1
58+
```
59+
60+
## Output
61+
62+
The output will display the complete path of the recovery services vault where the storage account is registered. Here is a sample output:
63+
64+
```output
65+
Found Storage account afsaccount registered in vault: /subscriptions/ ef4ad5a7-c2c0-4304-af80-af49f49af3d1/resourceGroups/azurefiles/providers/Microsoft.RecoveryServices/vaults/azurefilesvault123
66+
```
67+
68+
## Next steps
69+
70+
Learn how to [Backup Azure File Shares from the Azure portal](https://docs.microsoft.com/azure/backup/backup-afs)

0 commit comments

Comments
 (0)