I want to create a VM Scale set and use a snapshot as base for my windows VMs. As the Set-AzureRmVmssStorageProfile only accepts images my first try was to convert the snapshot to an image by use:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
But in this case the image that is created has no Source Blob URI:
what gives me the error:
New-AzureRmVmss : The URI Microsoft.Azure.Commands.Compute.Automation.Models.PSImage does not look to be correct blob URI.
On my deploy commands for azure:
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" `
-Image $ImgRef -OsDiskOsType Windows -OsDiskName "C"
Set-AzureRmVmssOSProfile -ComputerNamePrefix $vmNamePrefix -AdminUsername $adminUsername -AdminPassword $adminPassword -VirtualMachineScaleSet $vmss
New-AzureRmVmss -ResourceGroupName $currentrg -Name $vmssName -VirtualMachineScaleSet $vmss -Verbose -ErrorAction Stop;
Is there a other way to create the image or set a source blob uri? Or is it possible to use a snapshot for creating an VM Scale Set?
-- Edit 1 --
Afer the hint from Charles Xu I changhed the image creation to first create a dik, but I still get the same error. New Code is:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$storageType = 'Standard_LRS'
$diskName = "myDisk"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $rgName -DiskName $diskName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig