Get-AzRecoveryServicesBackupItem ability to filter according to exact VM name
When using the commnand Get-AzRecoveryServicesBackupItem with a VM name, a list of backup items containing the name is returned.
There should be a way to receive results with exact match of the vm name parameter
for example if I have 2 VMs with the name: VM1 and VM11, this command will return 2 items for each VM
$backupItem = Get-AzRecoveryServicesBackupItem -BackupManagementType "AzureVM" -WorkloadType "AzureVM" -Name "VM1" -VaultId $vault.ID
I will have to perform filtering on the result to verify I get the exact VM item I was looking for
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @pvrk.
Issue Details
When using the commnand Get-AzRecoveryServicesBackupItem with a VM name, a list of backup items containing the name is returned.
There should be a way to receive results with exact match of the vm name parameter
for example if I have 2 VMs with the name: VM1 and VM11, this command will return 2 items for each VM
$backupItem = Get-AzRecoveryServicesBackupItem -BackupManagementType "AzureVM" -WorkloadType "AzureVM" -Name "VM1" -VaultId $vault.ID
I will have to perform filtering on the result to verify I get the exact VM item I was looking for
| Author: | assaf-grth |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
@assaf-grth : For more details, can you please run the "Get-AzRecoveryServicesBackupContainer" cmdlet with the same parameters and let us know if that is giving the exact result?
@assaf-grth : Can you also retry using the "FriendlyName" option instead of "-Name" option for "Get-AzRecoveryServicesBackupItem" cmdlet?
I get even more results with names which are not related to my input
I get even more results with names which are not related to my input
May I know the above response is for which query? Basically please run 2 commands (Get-AzBackupContainer and Get-AzBackupItem with Friendly name parameter) and please provide the response separately.
I'm limited with the information I can provide Is there specific data you would like to inspect?
@assaf-grth - We have tried the different combinations at our end and created a backlog item for the permanent fix. As a stop gap solution , can you please try the below: Run $container=Get-AzRecoveryServicesBackupContainer command and pass VM name as the value for -FriendlyName parameter. Now run the Get-AzRecoveryServicesBackupItem command with -Container parameter and pass the container variable as value for the parameter. Sample: $Container=Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "testvm" -VaultId $vault.ID Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureVM -VaultId $vault.ID -FriendlyName "testvm"
Please let us know if this works for you.
@mepand I already figured a way
The result of Get-AzRecoveryServicesBackupItem with -Name parameter is a name with this format:
VM;container name;resource group name;vm name
On this string I filtered the vm I required using this command:
$vmBackupItem = $backupItem | Where-Object {$_.Name.EndsWith(";$($vm)")}
In case I'll have different problems with this way I will try your suggestion
Thanks for the assistance
Thanks for the quick response @assaf-grth . Glad to know that you are unblocked. As I mentioned above, we will be doing the permanent fix in one of the upcoming releases. Currently, since there is no more assistance needed from the PG team, I think we can close this issue. Incase you face some other issue, please feel free to reach out to us.
@assaf-grth thanks for sharing your workaround, I ended up using the same 3 years later. It's funny how we expect flag like -Name to match on name EXACTLY and it seems like a blocker but then we forget about our ability to use PS to just weed the list down after it's returned to us. You unblocked me there