Skip to content

Instantly share code, notes, and snippets.

@Oceanswave
Created April 19, 2022 03:50
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 Oceanswave/e3e920088e34617071bd0874fef02c49 to your computer and use it in GitHub Desktop.
Save Oceanswave/e3e920088e34617071bd0874fef02c49 to your computer and use it in GitHub Desktop.
Download SharePoint 2019 Image
$rgName = "sp2019"
$rgLocation = "eastus2"
$vmSize = "Standard_D2s_v3"
$vmName = "sp2019-test"
$vmAuthenticationType = "password" # ssh
$vmImage = "MicrosoftSharePoint:MicrosoftSharePointServer:sp2019:latest"
$vmUserName = "sp2019"
$vmPassword = "P@ssw0rd1234"
$vmStorageAccountName = "sp2019vm"
$vmStorageAccountSku = "Standard_LRS"
$vmVNetName = "sp2019-vnet"
$vmVNetAddressPrefix = "10.0.0.0/16"
$vmSubnetName = "sp2019-subnet"
$vmSubnetAddressPrefix = "10.0.0.0/24"
$vhdPrefix = "sp19"
az group create --name $rgName --location $rgLocation
az vm create `
--name $vmName `
--resource-group $rgName `
--accelerated-networking $false `
--accept-term `
--admin-username $vmUserName `
--admin-password $vmPassword `
--authentication-type $vmAuthenticationType `
--data-disk-delete-option "Delete" `
--image $vmImage `
--os-disk-delete-option "Delete" `
--public-ip-sku "Standard" `
--size $vmSize `
--storage-account $vmStorageAccountName `
--storage-sku $vmStorageAccountSku `
--subnet $vmSubnetName `
--subnet-address-prefix $vmSubnetAddressPrefix `
--use-unmanaged-disk `
--vnet-name $vmVNetName `
--vnet-address-prefix $vmVNetAddressPrefix
az vm deallocate --resource-group $rgName --name $vmName
az vm generalize --resource-group $rgName --name $vmName
$vhd = $(ConvertFrom-Json $($(az vm capture --resource-group $rgName --name $vmName --vhd-name-prefix $vhdPrefix -o json) -join ""))
$vhdUri = $vhd.properties.storageProfile.osDisk.image.uri
az storage copy -s $vhdUri -d "C:\vhd\$vmName.vhd" -- --overwrite=prompt --check-md5 NoCheck
az group delete --name $rgName --yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment