{"id":5498,"date":"2022-01-30T02:39:53","date_gmt":"2022-01-30T02:39:53","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=5498"},"modified":"2022-12-02T02:46:57","modified_gmt":"2022-12-02T02:46:57","slug":"new-azvm-required-parameter-storageprofile","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/new-azvm-required-parameter-storageprofile","title":{"rendered":"New-AzVM : Required parameter &#8220;storageProfile&#8221;"},"content":{"rendered":"\n<p>Recently I was using the script&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/azure\/virtual-machines\/scripts\/virtual-machines-windows-powershell-upload-generalized-script\">here<\/a>&nbsp;to upload a VHD to Azure for Deployment to a VM<\/p>\n\n\n\n<p>Upon the upload or the file<\/p>\n\n\n\n<p>New-AzVM -VM $vm -ResourceGroupName $resourceGroup -Location $location<\/p>\n\n\n\n<p>i got<\/p>\n\n\n\n<p>ErrorCode: InvalidParameter<br>ErrorMessage: Required parameter \u2018storageProfile\u2019 is missing (null).<br>ErrorTarget: storageProfile<br>StatusCode: 400<br>ReasonPhrase: Bad Request<\/p>\n\n\n\n<p>The script needs changing , I removed the need for the Azure Image and it does it directly from the uploaded VHD<\/p>\n\n\n<div class=\"wp-block-wab-pastacode\">\n\t<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\"># Provide values for the variables<br\/>$resourceGroup = \u2019myResourceGroup\u2019<br\/>$location = \u2019EastUS\u2019<br\/>$storageaccount = \u2019mystorageaccount\u2019<br\/>$storageType = \u2019Standard_LRS\u2019<br\/>$containername = \u2019mycontainer\u2019<br\/>$localPath = \u2019C:\\Users\\Public\\Documents\\Hyper-V\\VHDs\\generalized.vhd\u2019<br\/>$vmName = \u2019myVM\u2019<br\/>$vhdName = \u2019myUploadedVhd.vhd\u2019<br\/>$diskSizeGB = \u2019128\u2019<br\/>$subnetName = \u2019mySubnet\u2019<br\/>$vnetName = \u2019myVnet\u2019<br\/>$ipName = \u2019myPip\u2019<br\/>$nicName = \u2019myNic\u2019<br\/>$nsgName = \u2019myNsg\u2019<br\/>$ruleName = \u2019myRdpRule\u2019<br\/>$computerName = \u2019myComputerName\u2019<br\/>$vmSize = \u2019Standard_DS1_v2\u2019<br\/><br\/># Get the username and password to be used for the administrators account on the VM. <br\/># This is used when connecting to the VM using RDP.<br\/><br\/>$cred = Get-Credential<br\/><br\/># Upload the VHD<br\/>New-AzResourceGroup -Name $resourceGroup -Location $location<br\/>New-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccount -Location $location `<br\/>\t-SkuName $storageType -Kind &quot;Storage&quot;<br\/>$urlOfUploadedImageVhd = (\u2018https:\/\/\u2019 + $storageaccount + \u2019.blob.core.windows.net\/\u2019 + $containername + \u2019\/\u2019 + $vhdName)<br\/>Add-AzVhd -ResourceGroupName $resourceGroup -Destination $urlOfUploadedImageVhd `<br\/>    -LocalFilePath $localPath<br\/><br\/># Note: Uploading the VHD may take awhile!<br\/><br\/># Create OS managed disk<br\/>$SAId = (Get-AzStorageAccount -ResourceGroupName $RGName -Name $SAName).Id<br\/>$OSDiskConfig = New-AzDiskConfig -AccountType &quot;$storageType -Location $location -DiskSizeGB $diskSizeGB `<br\/>    -SourceUri $urlOfUploadedImageVhd -StorageAccountId $storageaccount -CreateOption &quot;Import&quot;<br\/>$OSDisk = New-AzDisk -DiskName $vhdName -Disk $OSDiskConfig -ResourceGroupName $resourceGroup<br\/> <br\/># Create the networking resources<br\/>$singleSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0\/24<br\/>$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup -Location $location `<br\/>\t-AddressPrefix 10.0.0.0\/16 -Subnet $singleSubnet<br\/>$pip = New-AzPublicIpAddress -Name $ipName -ResourceGroupName $resourceGroup -Location $location `<br\/>    -AllocationMethod Dynamic<br\/>$rdpRule = New-AzNetworkSecurityRuleConfig -Name $ruleName -Description \u2019Allow RDP\u2019 -Access Allow `<br\/>\t-Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix Internet -SourcePortRange * `<br\/>\t-DestinationAddressPrefix * -DestinationPortRange 3389<br\/>$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location `<br\/>\t-Name $nsgName -SecurityRules $rdpRule<br\/>$nic = New-AzNetworkInterface -Name $nicName -ResourceGroupName $resourceGroup -Location $location `<br\/>\t-SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id<br\/>$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroup -Name $vnetName<br\/><br\/># Start building the VM configuration<br\/>$vm = New-AzVMConfig -VMName $vmName -VMSize $vmSize<br\/><br\/># Set the VM image as source image for the new VM<br\/>$vm = Set-AzVMOSDisk -VM $vm -ManagedDiskId $OSDisk.Id -CreateOption &quot;Attach&quot; -Windows<br\/><br\/># Finish the VM configuration and add the NIC.<br\/>$vm = Set-AzVMOSDisk -VM $vm  -DiskSizeInGB $diskSizeGB -CreateOption FromImage -Caching ReadWrite<br\/>$vm = Set-AzVMOperatingSystem -VM $vm -Windows -ComputerName $computerName -Credential $cred `<br\/>\t-ProvisionVMAgent -EnableAutoUpdate<br\/>$vm = Add-AzVMNetworkInterface -VM $vm -Id $nic.Id<br\/><br\/># Create the VM<br\/>New-AzVM -VM $vm -ResourceGroupName $resourceGroup -Location $location<br\/><br\/># Verify that the VM was created<br\/>$vmList = Get-AzVM -ResourceGroupName $resourceGroup<br\/>$vmList.Name<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div><\/div>\n\n\n\n<p>$NewVMConfig = Set-AzVMOSDisk -VM $NewVMConfig -ManagedDiskId $OSDisk.Id -CreateOption &#8220;Attach&#8221; -Windows<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was using the script&nbsp;here&nbsp;to upload a VHD to Azure for Deployment to a VM Upon the upload or the file New-AzVM -VM $vm -ResourceGroupName $resourceGroup [&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":[3708],"class_list":["post-5498","post","type-post","status-publish","format-standard","hentry","category-research","tag-required-parameter-storageprofile"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/5498","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=5498"}],"version-history":[{"count":3,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/5498\/revisions"}],"predecessor-version":[{"id":6458,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/5498\/revisions\/6458"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=5498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=5498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=5498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}