AzureFiles backup restore

Brass Contributor

Hello,
I created AzureFiles backup and want to restore So I use this script:

Select-AzureRmSubscription -SubscriptionId $AzureSubscriptionId
$Vault = Get-AzureRmRecoveryServicesVault -Name $BackupVault
Set-AzureRmRecoveryServicesVaultContext -Vault $Vault
$NamedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureStorage –Status Registered -FriendlyName $FileShareName
$BackupItem = Get-AzureRmRecoveryServicesBackupItem –Container $NamedContainer –WorkloadType AzureFiles
$StartDate = (Get-Date).AddDays(-7)
$EndDate = Get-Date
$RecoveryPoint = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $StartDate.ToUniversalTime() -EndDate $EndDate.ToUniversalTime() 
$RestoreJob = Restore-AzureRmRecoveryServicesBackupItem -RecoveryPoint $RecoveryPoint[0] -StorageAccountName $StorageAccount -StorageAccountResourceGroupName $ResourceGroupName

But I get an error:

Get-AzureRmRecoveryServicesBackupRecoveryPoint : Cannot convert 'System.Object[]' to the type 
'Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ItemBase' required by parameter 'Item'. Specified 
method is not supported.
At line:46 char:71
+ ... -AzureRmRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartD ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmReco...upRecoveryPoint], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.GetAzureRmR
ecoveryServicesBackupRecoveryPoint

How to solve this?

2 Replies

@Patrick Sanouiller 

 

Based on the error message $BackupItem is array value, so use foreach loop in the script.

1. Does $NamedContainer have an object reference?

2. Does $BackupItem have an object reference?