Forum Discussion

nirmalmcse02's avatar
nirmalmcse02
Copper Contributor
Oct 07, 2021
Solved

Azure PowerShell Script to create Virtual machine from Azure Recovery Service vault restore

I am using below PowerShell script to create VM from Recovery Service Vault restore however this is not working. Could you please help me to debug? ==================================================...
  • omarmciver's avatar
    omarmciver
    Oct 14, 2021

    Hey nirmalmcse02,

     

    You also seem to be setting the VM OS Disk twice.

    Set-AzVMOSDisk -VM $VMCreateName -Name "$VMRestoreName" -VhdUri $VMObject.'properties.StorageProfile'.OsDisk -CreateOption "Attach"
    
    Set-AzVMOSDisk -VM $VMCreateName -Name "test1-restored-OsDisk" -VhdUri $VMObject.'properties.storageProfile'.osDisk.vhd -CreateOption "Attach" -Windows
    $VMCreateName.StorageProfile.OsDisk.OsType = $VMObject.'properties.StorageProfile'.OsDisk.OsType

     

    Could you add:

    Write-Output $VMCreateName

     ...before the New-AzVM command.

     

    If you need to redact any of the content, please be sure to identity for where you had relative URIs vs absolute (i.e. https://resources.microsoft.com/subscriptions/987a.... . or just /subscriptions/987a.... .)

     

    Something in that object is using a relative URI where as the New-AzVM command is expecting an absolute URI.