Last active
August 29, 2015 14:14
-
-
Save nkpatterson/ce00ede9a03777aa1578 to your computer and use it in GitHub Desktop.
Provision Azure VMs with Chocolatey DSC
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]$StorageAccountName, | |
[Parameter(Mandatory=$True)] | |
[string]$DscConfigurationPath, | |
[Parameter()] | |
[string]$DscConfigurationName, | |
[Parameter()] | |
[string]$ServiceName, | |
[Parameter()] | |
[string[]]$VmNames, | |
[Parameter()] | |
[string]$AdminUsername, | |
[Parameter()] | |
[string]$AdminPassword, | |
[Parameter()] | |
[string]$DscContainerName = "misc", | |
[Parameter()] | |
[string]$VhdContainerName = "vhds", | |
[Parameter()] | |
[string]$Location = "East US" | |
) | |
$storageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary | |
$storage = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageAccountKey | |
$storageEndpoint = (Get-AzureStorageAccount -StorageAccountName $StorageAccountName).Endpoints | where {$_ -like "*.blob.*"} | select -First 1 | |
$dscFileName = [System.IO.Path]::GetFileName($DscConfigurationPath) + ".zip" | |
Publish-AzureVMDSCConfiguration -ConfigurationPath $DscConfigurationPath -StorageContext $storage -ContainerName $DscContainerName -Force | |
foreach ($name in $VmNames) { | |
$mediaLocation = "{0}{1}/{2}.vhd" -f $storageEndpoint, $VhdContainerName, $name | |
$vm = New-AzureVMConfig -Name $name -InstanceSize Small -ImageName "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201412.01-en.us-127GB.vhd" -MediaLocation $mediaLocation | |
$vm = Add-AzureProvisioningConfig -VM $vm -Windows -AdminUsername $AdminUsername -Password $AdminPassword | |
$vm = Set-AzureVMDSCExtension -VM $vm -ConfigurationArchive $dscFileName -StorageContext $storage -Containername $DscContainerName -ConfigurationName $DscConfigurationName | |
New-AzureVM -VM $vm -Location $Location -ServiceName $ServiceName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment