{"id":3020,"date":"2017-12-03T12:48:44","date_gmt":"2017-12-03T12:48:44","guid":{"rendered":"http:\/\/pariswells.com\/blog\/?p=3020"},"modified":"2017-12-03T12:48:44","modified_gmt":"2017-12-03T12:48:44","slug":"powershell-to-create-a-vm-from-an-copied-vhd","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/powershell-to-create-a-vm-from-an-copied-vhd","title":{"rendered":"Powershell to Create a VM from an copied VHD"},"content":{"rendered":"<p>If you are using Windows 10 or have Powershell 5 installed run<\/p><div><div id=\"highlighter_286814\" class=\"syntaxhighlighter  powershell\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"code\"><div class=\"container\"><div class=\"line number1 index0 alt2\"><code class=\"powershell plain\">Install-Module AzureRM<\/code><\/div><\/div><\/td><\/tr><\/tbody><\/table><\/div><\/div><p>Once installed, use the following to log into Azure in an interactive fashion:<\/p><div><div id=\"highlighter_333437\" class=\"syntaxhighlighter  powershell\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"gutter\"><div class=\"line number1 index0 alt2\">\u00a0<\/div><\/td><td class=\"code\"><div class=\"container\"><div class=\"line number1 index0 alt2\"><code class=\"powershell plain\">Login-AzureRmAccount<\/code><\/div><\/div><\/td><\/tr><\/tbody><\/table><\/div><\/div><p>Edit these lines , use\u00a0Get-AzureRmVirtualNetwork to get your VirtualNetwork Name<\/p><p>Run these\u00a0<\/p><p>$vmName = &#8220;%vmname%&#8221;<br \/>$resourceGroupName = &#8220;%resourcename%&#8221;<br \/><br \/>$virtualNetworkName = &#8220;%virtualnetworkname%&#8221;<br \/>$locationName = &#8220;australiaeast&#8221;<br \/>$vmsize = &#8220;Standard_A1&#8221;<br \/>$destinationVhd = &#8220;https:\/\/vmname.blob.core.windows.net\/vhds\/osdisk.vhd&#8221;<\/p><p>$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName <br \/>$publicIp = New-AzureRmPublicIpAddress -Name $vmName -ResourceGroupName $ResourceGroupName -Location $locationName -AllocationMethod Dynamic<br \/>$networkInterface = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Name $vmName -Location $locationName -SubnetId $virtualNetwork.Subnets[0].Id -PublicIpAddressId $publicIp.Id <br \/>$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmsize<br \/>$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $networkInterface.Id<br \/>$vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name $vmName -VhdUri $destinationVhd -CreateOption Attach -Windows<br \/>$vm = New-AzureRmVM -VM $vmConfig -Location $locationName -ResourceGroupName $resourceGroupName<\/p>","protected":false},"excerpt":{"rendered":"<p>If you are using Windows 10 or have Powershell 5 installed runInstall-Module AzureRMOnce installed, use the following to log into Azure in an interactive fashion:\u00a0Login-AzureRmAccountEdit these lines [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2257,2256],"class_list":["post-3020","post","type-post","status-publish","format-standard","hentry","category-research","tag-create-a-vm-from-an-copied-vhd","tag-vhd"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/3020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=3020"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/3020\/revisions"}],"predecessor-version":[{"id":3021,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/3020\/revisions\/3021"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=3020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=3020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=3020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}