Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Created July 31, 2017 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjwaight/af30918747feca08839831c47a05f454 to your computer and use it in GitHub Desktop.
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
[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