New-AzVM : Required parameter “storageProfile”

Recently I was using the script here to upload a VHD to Azure for Deployment to a VM

Upon the upload or the file

New-AzVM -VM $vm -ResourceGroupName $resourceGroup -Location $location

i got

ErrorCode: InvalidParameter
ErrorMessage: Required parameter ‘storageProfile’ is missing (null).
ErrorTarget: storageProfile
StatusCode: 400
ReasonPhrase: Bad Request

The script needs changing , I removed the need for the Azure Image and it does it directly from the uploaded VHD

# Provide values for the variables
$resourceGroup = ’myResourceGroup’
$location = ’EastUS’
$storageaccount = ’mystorageaccount’
$storageType = ’Standard_LRS’
$containername = ’mycontainer’
$localPath = ’C:\Users\Public\Documents\Hyper-V\VHDs\generalized.vhd’
$vmName = ’myVM’
$vhdName = ’myUploadedVhd.vhd’
$diskSizeGB = ’128’
$subnetName = ’mySubnet’
$vnetName = ’myVnet’
$ipName = ’myPip’
$nicName = ’myNic’
$nsgName = ’myNsg’
$ruleName = ’myRdpRule’
$computerName = ’myComputerName’
$vmSize = ’Standard_DS1_v2’

# Get the username and password to be used for the administrators account on the VM.
# This is used when connecting to the VM using RDP.

$cred = Get-Credential

# Upload the VHD
New-AzResourceGroup -Name $resourceGroup -Location $location
New-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccount -Location $location `
-SkuName $storageType -Kind "Storage"
$urlOfUploadedImageVhd = (‘https://’ + $storageaccount + ’.blob.core.windows.net/’ + $containername + ’/’ + $vhdName)
Add-AzVhd -ResourceGroupName $resourceGroup -Destination $urlOfUploadedImageVhd `
-LocalFilePath $localPath

# Note: Uploading the VHD may take awhile!

# Create OS managed disk
$SAId = (Get-AzStorageAccount -ResourceGroupName $RGName -Name $SAName).Id
$OSDiskConfig = New-AzDiskConfig -AccountType "$storageType -Location $location -DiskSizeGB $diskSizeGB `
-SourceUri $urlOfUploadedImageVhd -StorageAccountId $storageaccount -CreateOption "Import"
$OSDisk = New-AzDisk -DiskName $vhdName -Disk $OSDiskConfig -ResourceGroupName $resourceGroup

# Create the networking resources
$singleSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroup -Location $location `
-AddressPrefix 10.0.0.0/16 -Subnet $singleSubnet
$pip = New-AzPublicIpAddress -Name $ipName -ResourceGroupName $resourceGroup -Location $location `
-AllocationMethod Dynamic
$rdpRule = New-AzNetworkSecurityRuleConfig -Name $ruleName -Description ’Allow RDP’ -Access Allow `
-Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix Internet -SourcePortRange * `
-DestinationAddressPrefix * -DestinationPortRange 3389
$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location $location `
-Name $nsgName -SecurityRules $rdpRule
$nic = New-AzNetworkInterface -Name $nicName -ResourceGroupName $resourceGroup -Location $location `
-SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id
$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroup -Name $vnetName

# Start building the VM configuration
$vm = New-AzVMConfig -VMName $vmName -VMSize $vmSize

# Set the VM image as source image for the new VM
$vm = Set-AzVMOSDisk -VM $vm -ManagedDiskId $OSDisk.Id -CreateOption "Attach" -Windows

# Finish the VM configuration and add the NIC.
$vm = Set-AzVMOSDisk -VM $vm -DiskSizeInGB $diskSizeGB -CreateOption FromImage -Caching ReadWrite
$vm = Set-AzVMOperatingSystem -VM $vm -Windows -ComputerName $computerName -Credential $cred `
-ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzVMNetworkInterface -VM $vm -Id $nic.Id

# Create the VM
New-AzVM -VM $vm -ResourceGroupName $resourceGroup -Location $location

# Verify that the VM was created
$vmList = Get-AzVM -ResourceGroupName $resourceGroup
$vmList.Name

$NewVMConfig = Set-AzVMOSDisk -VM $NewVMConfig -ManagedDiskId $OSDisk.Id -CreateOption “Attach” -Windows

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...