Skip to content

Instantly share code, notes, and snippets.

@sochan1
Created October 10, 2016 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sochan1/b7066311fed3463d9470868144bb3d96 to your computer and use it in GitHub Desktop.
Save sochan1/b7066311fed3463d9470868144bb3d96 to your computer and use it in GitHub Desktop.
createm vm from existing vhd
$resourceGroup="test-DR-RG"
$location = "East US2"
$vmname='test-sc-cd02'
#Collecting required parameters for creating VM
$StorageAccountName='testvhdstorage02'
$vnet=Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroup
$subnetname = $vnet.Subnets.name
$vnetname=$vnet.Name
$subnetid=Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetname
$nicname=$vmname + '-NIC-IP'
$nic=New-AzureRmNetworkInterface -Name 'test-sc-cd02-nic' -ResourceGroupName $resourceGroup -Location $location -Subnet $subnetid -IpConfigurationName $nicname -PrivateIpAddress '192.168.0.9'
$wincred=Get-Credential -Message 'Type username and password that will be created for VM'
$VM=New-AzureRmVMConfig -VMName $vmname -VMSize 'Basic_A3'
$VM= Add-AzureRmVMNetworkInterface -VM $VM -Id $nic.Id
$VM=Set-AzureRmVMOperatingSystem -VM $VM -Windows -ComputerName $vmname -Credential $wincred -EnableAutoUpdate -ProvisionVMAgent
#$VM=Set-AzureRmVMSourceImage -VM $VM -PublisherName 'MicrosoftWindowsServer' -Offer 'WindowsServer' -Skus '2012-R2-Datacenter' -Version latest
$VM=Set-AzureRmVMOSDisk -VM $VM -Name 'test-sc-cd02-CLONE_2-000002.vhd' -VhdUri "https://testvhdstorage02.blob.core.windows.net/allvhdconatiner/test-sc-cd02-CLONE_2-000002.vhd" -CreateOption FromImage -Windows -Caching ReadWrite
new-azurermvm -VM $VM -ResourceGroupName $resourceGroup -Location $location
PS C:\Windows\system32> new-azurermvm -VM $VM -ResourceGroupName $resourceGroup -Location $location
new-azurermvm : Cannot specify user image overrides for a disk already defined in the specified image reference.
ErrorCode: InvalidParameter
ErrorMessage: Cannot specify user image overrides for a disk already defined in the specified image reference.
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 912398ea-88c3-4869-861b-test123At line:1 char:1
+ new-azurermvm -VM $VM -ResourceGroupName $resourceGroup -Location $location
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
PS C:\Windows\system32>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment