Alex D
Alex D

Reputation: 828

How do you create Azure VM from VHD with unmanaged disk?

I have a Datacenter 2016 server with unmanaged disk. I need to be able to replicate this VM and continue using an unmanaged disk.

Do I need to provision the VM i want to replicate? Or can I just use the VHD in storage to create a new VM?

Here is my powershell script so far. Note that I tried to provision a VM

New-AzVm `
    -ResourceGroupName "myResource" `
    -Name "myVM" `
    -ImageName "" ` //IS THIS WHERE YOU WOULD PUT A VHD? 
    -Location "West US 2" `
    -VirtualNetworkName "my-vnet" `
    -SubnetName "default" `
    -SecurityGroupName "myvmNSG" `
    -OpenPorts 3389, 80, 443

Upvotes: 0

Views: 547

Answers (1)

Charles Xu
Charles Xu

Reputation: 31384

If you want to create an unmanaged VM from the VHD file, you can use the VM config. Here is an example using the existing NIC and VNet, you can also create the new one for it:

$NIC = Get-AzNetworkInterface -ResourceGroupName charlesUnmanaged -Name azurevm938
$VirtualMachine = New-AzVMConfig -VMName "azurevm" -VMSize "Standard_DS3"
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -Name "unmanagedos" -VhdUri $OSDiskUri -CreateOption Attach -Linux
New-AzVM -ResourceGroupName "charlesUnmanaged" -Location "East US" -VM $VirtualMachine -Verbose 

Upvotes: 1

Related Questions