Using Powershell to create VMs in Azure

%3CLINGO-SUB%20id%3D%22lingo-sub-1602661%22%20slang%3D%22en-US%22%3EUsing%20Powershell%20to%20create%20VMs%20in%20Azure%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1602661%22%20slang%3D%22en-US%22%3E%3CP%3EI%20Have%20a%20powershell%20script%20we%20use%20to%20create%20VM.%20It%20uses%20a%20generalized%20snapshot%20to%20make%20the%20build%20but%20I%20want%20to%20switch%20to%20using%20an%20image%20so%20I%20can%20load%20the%20image%20instal%20a%20gallery%20instead%20of%20having%20to%20copy%20the%20same%20snapshot%20to%20different%20RGs.%20I%20cam%20create%20and%20images%20from%20the%20snapshot%20but%20I%20cant%20work%20our%20how%20to%20modify%20my%20power%20shell%20to%20refer%20to%20the%20image%20instead%20of%20the%20snapshot%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20relevant%20section%3A%20is%3C%2FP%3E%3CP%3E%24snapshot%20%3D%20'SLES12-SP4-xxxxxxxx-BUILD-0001'%3C%2FP%3E%3CP%3E%24snapshotName%20%3D%20Get-AzureRmSnapshot%20-ResourceGroupName%20%24rg%20-SnapshotName%20%24snapshot%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24diskConfig%20%3D%20New-AzureRmDiskConfig%20-DiskSizeGB%20200%20-AccountType%20%24storageType%20-Location%20%24region%20-SourceResourceId%20%24snapshotName.Id%20-OsType%20Linux%20-CreateOption%20Copy%3C%2FP%3E%3CP%3E%24vmDisk%20%3D%20New-AzureRmDisk%20-ResourceGroupName%20%24rg%20-DiskName%20%24vmOSdiskName%20-Disk%20%24diskConfig%3C%2FP%3E%3CP%3E%24MyVM%20%3D%20Set-AzureRmVMOSDisk%20-VM%20%24MyVM%20-ManagedDiskId%20%24vmDisk.Id%20-CreateOption%20Attach%20-Linux%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20advice%20on%20the%20syntax%20please%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

I Have a powershell script we use to create VM. It uses a generalized snapshot to make the build but I want to switch to using an image so I can load the image instal a gallery instead of having to copy the same snapshot to different RGs. I cam create and images from the snapshot but I cant work our how to modify my power shell to refer to the image instead of the snapshot

 

the relevant section: is

$snapshot = 'SLES12-SP4-xxxxxxxx-BUILD-0001'

$snapshotName = Get-AzureRmSnapshot -ResourceGroupName $rg -SnapshotName $snapshot

 

$diskConfig = New-AzureRmDiskConfig -DiskSizeGB 200 -AccountType $storageType -Location $region -SourceResourceId $snapshotName.Id -OsType Linux -CreateOption Copy

$vmDisk = New-AzureRmDisk -ResourceGroupName $rg -DiskName $vmOSdiskName -Disk $diskConfig

$MyVM = Set-AzureRmVMOSDisk -VM $MyVM -ManagedDiskId $vmDisk.Id -CreateOption Attach -Linux

 

Can anyone advice on the syntax please

0 Replies