Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure DevTest Labs Deploy sample script
#Requires -Version 3.0
#Requires -Module AzureRM.Resources
#Requires -Module Azure.Storage
# deploy bin folder
#..\scripts\Deploy-AzureResourceGroup.ps1 -ResourceGroupName 'psugdemoRG770838' -ResourceGroupLocation 'japanwest' -TemplateFile '..\templates\windowsvirtualmachine.json' -TemplateParametersFile '..\templates\windowsvirtualmachine.parameters.json'
Param(
[string] [Parameter(Mandatory=$true)] $ResourceGroupLocation,
[string] $ResourceGroupName = 'psugdemoRG770838',
[string] $TemplateFile = '..\Templates\WindowsVirtualMachine.json',
[string] $TemplateParametersFile = '..\Templates\WindowsVirtualMachine.parameters.json'
)
Import-Module Azure -ErrorAction SilentlyContinue
try {
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("VSAzureTools-$UI$($host.name)".replace(" ","_"), "2.8")
} catch { }
Set-StrictMode -Version 3
$OptionalParameters = New-Object -TypeName Hashtable
$TemplateFile = [System.IO.Path]::Combine($PSScriptRoot, $TemplateFile)
$TemplateParametersFile = [System.IO.Path]::Combine($PSScriptRoot, $TemplateParametersFile)
# Create or update the resource group using the specified template file and template parameters file
New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFile `
-TemplateParameterFile $TemplateParametersFile `
@OptionalParameters `
-Force -Verbose -nameFromTemplate 'psugdemo0409'
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"metadata": {
"description": "Computername for the Virtual Machine."
}
},
"userName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"password": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"size": {
"type": "string",
"defaultValue": "Standard_A2"
},
"labName": {
"type": "string",
"metadata": {
"description": "Deploy to Lab Name"
}
}
},
"resources": [
{
"apiVersion": "2015-05-21-preview",
"type": "Microsoft.DevTestLab/labs/virtualMachines",
"name": "[concat(parameters('labName'), '/', parameters('name'))]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "VirtualMachine"
},
"properties": {
"labVirtualNetworkId": "[concat(resourceGroup().id, '/providers/Microsoft.DevTestLab/labs/', parameters('labName'), '/virtualnetworks/dtlpsugdemo')]",
"notes": "Windows Server 2012 R2 Datacenter",
"galleryImageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2012-R2-Datacenter",
"osType": "Windows",
"version": "latest"
},
"size": "[parameters('size')]",
"userName": "[parameters('userName')]",
"password": "[parameters('password')]",
"isAuthenticationWithSshKey": false,
"artifacts": [
{
"artifactId": "[concat(resourceGroup().id, '/providers/Microsoft.DevTestLab/labs/', parameters('labName'), '/artifactSources/Public Repo/artifacts/windows-azurepowershell')]"
},
{
"artifactId": "[concat(resourceGroup().id, '/providers/Microsoft.DevTestLab/labs/', parameters('labName'), '/artifactSources/Public Repo/artifacts/windows-git')]"
}
],
"labSubnetName": "DtlpsugdemoSubnet",
"disallowPublicIpAddress": false,
"osType": ""
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": { "value": "psugdev001" },
"userName": { "value": "admin" },
"password": { "value": null },
"labName": { "value": "psugdemo" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment