Created
July 31, 2017 01:03
-
-
Save sjwaight/af30918747feca08839831c47a05f454 to your computer and use it in GitHub Desktop.
PowerShell script that can be used to create a VM Image in Azure based on a supplied VHD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True)] | |
[string]$imageResourceGroupName, | |
[Parameter(Mandatory=$True)] | |
[string]$imageResourceGroupAzureRegion, | |
[Parameter(Mandatory=$True)] | |
[string]$osDiskVhdUri, | |
[Parameter(Mandatory=$True)] | |
[string]$baselineImageName, | |
[Parameter(Mandatory=$True)] | |
[string]$buildNumber | |
) | |
# Build the VM Image name based on a static string and the VSTS build number | |
$vmImageName = $baselineImageName + "-" + $buildNumber; | |
# Create new Image Config in the right region | |
$imageConfig = New-AzureRmImageConfig -Location $imageResourceGroupAzureRegion | |
# Add OS disk (output from our Packer build) | |
Set-AzureRmImageOsDisk -Image $imageConfig -OsType 'Windows' -OsState 'Generalized' -BlobUri $osDiskVhdUri | |
# Create new Image | |
New-AzureRmImage -Image $imageConfig -ImageName $vmImageName -ResourceGroupName $imageResourceGroupName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment