AzureFiles backup restore

%3CLINGO-SUB%20id%3D%22lingo-sub-756395%22%20slang%3D%22en-US%22%3EAzureFiles%20backup%20restore%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-756395%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3CBR%20%2F%3EI%20created%20AzureFiles%20backup%20and%20want%20to%20restore%20So%20I%20use%20this%20script%3A%3C%2FP%3E%3CPRE%3E%3CEM%3ESelect-AzureRmSubscription%20-SubscriptionId%20%24AzureSubscriptionId%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24Vault%20%3D%20Get-AzureRmRecoveryServicesVault%20-Name%20%24BackupVault%20%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3ESet-AzureRmRecoveryServicesVaultContext%20-Vault%20%24Vault%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24NamedContainer%20%3D%20Get-AzureRmRecoveryServicesBackupContainer%20-ContainerType%20AzureStorage%20%E2%80%93Status%20Registered%20-FriendlyName%20%24FileShareName%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24BackupItem%20%3D%20Get-AzureRmRecoveryServicesBackupItem%20%E2%80%93Container%20%24NamedContainer%20%E2%80%93WorkloadType%20AzureFiles%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24StartDate%20%3D%20(Get-Date).AddDays(-7)%20%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24EndDate%20%3D%20Get-Date%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24RecoveryPoint%20%3D%20Get-AzureRmRecoveryServicesBackupRecoveryPoint%20-Item%20%24BackupItem%20-StartDate%20%24StartDate.ToUniversalTime()%20-EndDate%20%24EndDate.ToUniversalTime()%26nbsp%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%24RestoreJob%20%3D%20Restore-AzureRmRecoveryServicesBackupItem%20-RecoveryPoint%20%24RecoveryPoint%5B0%5D%20-StorageAccountName%20%24StorageAccount%20-StorageAccountResourceGroupName%20%24ResourceGroupName%3C%2FEM%3E%3C%2FPRE%3E%3CP%3EBut%20I%20get%20an%20error%3A%3C%2FP%3E%3CPRE%3E%3CSTRONG%3EGet-AzureRmRecoveryServicesBackupRecoveryPoint%20%3A%20Cannot%20convert%20'System.Object%5B%5D'%20to%20the%20type%20%0A'Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.ItemBase'%20required%20by%20parameter%20'Item'.%20Specified%20%0Amethod%20is%20not%20supported.%0AAt%20line%3A46%20char%3A71%0A%2B%20...%20-AzureRmRecoveryServicesBackupRecoveryPoint%20-Item%20%24BackupItem%20-StartD%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~~~~~~~~~~%0A%20%20%20%20%2B%20CategoryInfo%20%20%20%20%20%20%20%20%20%20%3A%20InvalidArgument%3A%20(%3A)%20%5BGet-AzureRmReco...upRecoveryPoint%5D%2C%20ParameterBindingException%0A%20%20%20%20%2B%20FullyQualifiedErrorId%20%3A%20CannotConvertArgument%2CMicrosoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.GetAzureRmR%0AecoveryServicesBackupRecoveryPoint%3C%2FSTRONG%3E%3C%2FPRE%3E%3CP%3EHow%20to%20solve%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-756395%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Backup%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-770836%22%20slang%3D%22en-US%22%3ERe%3A%20AzureFiles%20backup%20restore%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-770836%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F30470%22%20target%3D%22_blank%22%3E%40Patrick%20Sanouiller%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBased%20on%20the%20error%20message%26nbsp%3B%24BackupItem%20is%20array%20value%2C%20so%20use%20foreach%20loop%20in%20the%20script.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-771693%22%20slang%3D%22en-US%22%3ERe%3A%20AzureFiles%20backup%20restore%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-771693%22%20slang%3D%22en-US%22%3E%3CP%3E1.%20Does%20%24NamedContainer%20have%20an%20object%20reference%3F%3C%2FP%3E%3CP%3E2.%20Does%20%24BackupItem%20have%20an%20object%20reference%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional 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
Highlighted

@Patrick Sanouiller 

 

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

Highlighted

1. Does $NamedContainer have an object reference?

2. Does $BackupItem have an object reference?