Oct 07 2021 05:28 AM
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
Oct 13 2021 09:53 AM
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
Oct 14 2021 06:14 AM
Oct 14 2021 07:06 AM
SolutionHey @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.
Oct 14 2021 07:06 AM
SolutionHey @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.