SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-2821967%22%20slang%3D%22en-US%22%3EAzure%20PowerShell%20Script%20to%20create%20Virtual%20machine%20from%20Azure%20Recovery%20Service%20vault%20restore%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2821967%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20using%20below%20PowerShell%20script%20to%20create%20VM%20from%20Recovery%20Service%20Vault%20restore%20however%20this%20is%20not%20working.%20Could%20you%20please%20help%20me%20to%20debug%3F%3C%2FP%3E%3CP%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%3CP%3EPowerShell%20Error%3C%2FP%3E%3CP%3ENew-AzVM%20%3A%20This%20operation%20is%20not%20supported%20for%20a%20relative%20URI.%3C%2FP%3E%3CP%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%3CP%3EBelow%20is%20my%20PowerShell%20Script%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%24ConfigBlobName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22resotevmconfig.json%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24ContainerName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22restorevmcontainername%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24TemplateName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22azuredeploy.json%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24JSONpath%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22exportjsonpath%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24StorageAccountRestore%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22storageaccountnamewhererestorewashappened%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24StorageAccountRestoreRGName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%22Resourcegroupnameofstorage%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24VMRestoreName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3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ore%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ESet-AzCurrentStorageAccount%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-Name%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24StorageAccountRestore%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-ResourceGroupName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24StorageAccountRestoreRGName%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ENew-AzStorageBlobSASToken%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-Container%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24ContainerName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-Blob%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24TemplateName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-Permission%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Br%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-FullUri%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EGet-AzStorageBlobContent%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-Container%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%24ContainerName%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-Blob%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPA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3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2842785%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20PowerShell%20Script%20to%20create%20Virtual%20machine%20from%20Azure%20Recovery%20Service%20vault%20restore%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2842785%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F828630%22%20target%3D%22_blank%22%3E%40nirmalmcse02%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20a%20look%20at%20the%20%24VMCreateName%20parameter.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20line%2018%20you%20use%20this%20to%20store%20a%20VM%20object%20(not%20just%20a%20name)%2C%20and%20then%20on%20line%2025%20you%20use%20this%20object%20to%20Add%20the%20network%20interface%20to%20the%20VM.%20At%20the%20same%20time%20you%20assign%20the%20return%20of%20that%20Add-AzVMNetworkInterface%20to%20the%20same%20variable.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETry%20changing%20line%2025%20from%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24VMCreateName%3DAdd-AzVMNetworkInterface%20-VM%20%24VMCreateName%20-Id%20%24VMNIC.Id%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3Bto%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EAdd-AzVMNetworkInterface%20-VM%20%24VMCreateName%20-Id%20%24VMNIC.Id%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EOmar%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2846204%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20PowerShell%20Script%20to%20create%20Virtual%20machine%20from%20Azure%20Recovery%20Service%20vault%20restore%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2846204%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F828630%22%20target%3D%22_blank%22%3E%40nirmalmcse02%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20also%20seem%20to%20be%20setting%20the%20VM%20OS%20Disk%20twice.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ESet-AzVMOSDisk%20-VM%20%24VMCreateName%20-Name%20%22%24VMRestoreName%22%20-VhdUri%20%24VMObject.'properties.StorageProfile'.OsDisk%20-CreateOption%20%22Attach%22%0A%0ASet-AzVMOSDisk%20-VM%20%24VMCreateName%20-Name%20%22test1-restored-OsDisk%22%20-VhdUri%20%24VMObject.'properties.storageProfile'.osDisk.vhd%20-CreateOption%20%22Attach%22%20-Windows%0A%24VMCreateName.StorageProfile.OsDisk.OsType%20%3D%20%24VMObject.'properties.StorageProfile'.OsDisk.OsType%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20add%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EWrite-Output%20%24VMCreateName%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B...before%20the%20New-AzVM%20command.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3EIf%20you%20need%20to%20redact%20any%20of%20the%20content%2C%20please%20be%20sure%20to%20identity%20for%20where%20you%20had%20relative%20URIs%20vs%20absolute%20(i.e.%20https%3A%2F%2Fresources.microsoft.com%2Fsubscriptions%2F987a....%26nbsp%3B.%20or%20just%26nbsp%3B%2Fsubscriptions%2F987a....%26nbsp%3B.)%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3ESomething%20in%20that%20object%20is%20using%20a%20relative%20URI%20where%20as%20the%20New-AzVM%20command%20is%20expecting%20an%20absolute%20URI.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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?

=============================================================

PowerShell Error

New-AzVM : This operation is not supported for a relative URI.

=================================================================

Below is my PowerShell Script

$ConfigBlobName = "resotevmconfig.json"
$ContainerName = "restorevmcontainername"
$TemplateName = "azuredeploy.json"
$JSONpath = "exportjsonpath"
$StorageAccountRestore = "storageaccountnamewhererestorewashappened"
$StorageAccountRestoreRGName = "Resourcegroupnameofstorage"
$VMRestoreName = "TestVMRESTORE"
$VMVNETName = "Virtualnetworkname"
$VMVNETRGName = "virtualnetworkRG"
$VMNICLocation = "location"
$VNETSubnetIndex= 1
$VMRestoreRGName = "RestorevmRGname"
# Step 8 - Prepare the VM restore
Set-AzCurrentStorageAccount -Name $StorageAccountRestore -ResourceGroupName $StorageAccountRestoreRGName
New-AzStorageBlobSASToken -Container $ContainerName -Blob $TemplateName -Permission r -FullUri
Get-AzStorageBlobContent -Container $ContainerName -Blob $ConfigBlobName -Destination $JSONpath
$VMObject = ((Get-Content -Path $JSONpath -Raw -Encoding Unicode)).TrimEnd([char]0x00) | ConvertFrom-Json
$VMCreateName = New-AzVMConfig -VMSize $VMObject.'properties.hardwareProfile'.vmSize -VMName "$VMRestoreName"
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
$VMNICName="$VMRestoreName"
$VNETName = Get-AzVirtualNetwork -Name "$VMVNETName" -ResourceGroupName "$VMVNETRGName"
$VMNIC = New-AzNetworkInterface -Name $VMNICName -ResourceGroupName "$VMRestoreRGName" -Location "$VMNICLocation" -SubnetId $VNETName.Subnets[$VNETSubnetIndex].Id 
$VMCreateName=Add-AzVMNetworkInterface -VM $VMCreateName -Id $VMNIC.Id
# Step 9 - Start the VM restore
New-AzVM -ResourceGroupName "$VMRestoreRGName" -Location "$VMNICLocation" -VM $VMCreateName -Verbose
=============================================================
3 Replies

Hey @nirmalmcse02 

 

Have a look at the $VMCreateName parameter.

 

On line 18 you use this to store a VM object (not just a name), and then on line 25 you use this object to Add the network interface to the VM. At the same time you assign the return of that Add-AzVMNetworkInterface to the same variable.

 

Try changing line 25 from

$VMCreateName=Add-AzVMNetworkInterface -VM $VMCreateName -Id $VMNIC.Id

 to

Add-AzVMNetworkInterface -VM $VMCreateName -Id $VMNIC.Id

 

Thanks

Omar

 

@omarmciver
I have replaced the lines as you have shared. Still this powershell is getting failed due to same error.
Please suggest.
Below is error.
Name : TestVMRESTORE
HardwareProfile : {VmSize}
NetworkProfile : {NetworkInterfaces}
StorageProfile : {OsDisk}



PS C:\> # Step 9 - Start the VM restore
PS C:\> New-AzVM -ResourceGroupName "$VMRestoreRGName" -Location "$VMNICLocation" -VM $VMCreateName -Verbose
New-AzVM : This operation is not supported for a relative URI.
At line:1 char:1
+ New-AzVM -ResourceGroupName "$VMRestoreRGName" -Location "$VMNICLocat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzVM], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
best response confirmed by nirmalmcse02 (Occasional Contributor)
Solution

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.