2

I have a PowerShell script that is used for deleting resource groups. Currently, it is not deleting due to RecoveryServicesVault and it having backup items (VMs).

I tried to delete the backup items using the command Disable-AzureRmRecoveryServicesBackupProtection, but it is doing a soft-delete and I need to wait for next 14 days to get it deleted permanently.

But as this PowerShell script is executing under a scheduled job, again the next day it will execute the above command and it will again wait another 14 days for the permanent deletion.

Is there any way to check whether the backup items are already soft-deleted and hold to execute it again?

I know the Az module has a command Get-AzRecoveryServicesBackupItem, which will give us the DeleteState. But this feature isn't in Get-AzureRmRecoveryServicesBackupItem.

Mike Oryszak
  • 298
  • 2
  • 10
Tinz
  • 123
  • 1
  • 9
  • What is preventing you from moving from the AzureRm to the Az module? The Az module will continue to be supported and will see new features added. – Mike Oryszak Jan 29 '20 at 18:03
  • Hi Mike, This script is in a server and lots of other scripts running in the system which are developed with AzureRm. I installed Az module also in the system and tried to Remove AzureRm and Import Az module in my current script(Current session). That is also not working. Is it possible to use both module in one system? if possible how can I use it. – Tinz Jan 30 '20 at 06:51
  • This MS Docs link has some info on migrating, but also has info on how to enable an alias for AzureRM to use the Az module that may help. https://azure.microsoft.com/en-us/blog/how-to-migrate-from-azurerm-to-az-in-azure-powershell/ – Mike Oryszak Jan 30 '20 at 16:26

1 Answers1

0

The AzureRm has been deprecated and will not be updated anymore, your option is to use the new Az module, and no need to change the original scripts, follow the steps below.

From your comment, please don't use the Az module mixed with the AzureRm module. Just uninstall the AzureRm module with Uninstall-Module -Name AzureRm -AllVersions, and follow this link to install the Az module.

Then in your powershell session, please don't use the old AzureRm commands together with the new Az commands, otherwise you will get an error.

If you don't want to change the original scripts, just close your powershell session and open a new one, run Enable-AzureRmAlias before all your other commands, then your AzureRm commands will work fine with the Az module, see this link.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54