Skip to content

Commit 53c0e0f

Browse files
committed
Merge pull request #2 from daltskin/VS-Chocolatey
Vs chocolatey
2 parents cc3a783 + b84a506 commit 53c0e0f

File tree

6 files changed

+401
-0
lines changed

6 files changed

+401
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ARMChocolatey
2+
3+
ARM Template to provision a VM complete with Visual Studio and any given Chocolatey packages.
4+
5+
<a href="https://portal.azure.com/#create/microsoft.template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2Fvisual-studio-dev-vm-chocolatey%2Fazuredeploy.json" target="_blank">
6+
<img src="http://azuredeploy.net/deploybutton.png"/>
7+
</a>
8+
<a href="http://armviz.io/#/?load=https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/visual-studio-dev-vm-chocolatey/azuredeploy.json" target="_blank">
9+
<img src="http://armviz.io/visualizebutton.png"/>
10+
</a>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cls
2+
$RGName = "RG-VS-Dev";
3+
$VMName = "jdvs2015vm";
4+
$VMUsername = "jmd";
5+
$DeployLocation = "West Europe"
6+
$ChocoPackages = "linqpad;sysinternals;agentransack;beyondcompare;fiddler4;visualstudiocode;imageresizerapp;gimp";
7+
$ARMTemplate = "C:\@SourceControl\GitHub\ARMChocolatey\AzureDeploy.json"
8+
9+
# 1. Login
10+
#Login-AzureRmAccount
11+
12+
#2. Create a resource group
13+
New-AzureRmResourceGroup -Name $RGName -Location $DeployLocation -Force
14+
15+
#3. Create resources within RG
16+
$sw = [system.diagnostics.stopwatch]::startNew()
17+
New-AzureRmResourceGroupDeployment -ResourceGroupName $RGName -TemplateFile $ARMTemplate -deployLocation $DeployLocation -vmName $VMName -vmAdminUserName $VMUsername -vmIPPublicDnsName $VMName -chocoPackages $ChocoPackages -Mode Complete -Force
18+
$sw | Format-List -Property *
19+
20+
#4. Get the RDP file
21+
Get-AzureRmRemoteDesktopFile -ResourceGroupName $RGName -Name $VMName -Launch -Verbose -Debug
22+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
param([Parameter(Mandatory=$true)][string]$chocoPackages)
2+
cls
3+
4+
#New-Item "c:\jdchoco" -type Directory -force | Out-Null
5+
#$LogFile = "c:\jdchoco\JDScript.log"
6+
#$chocoPackages | Out-File $LogFile -Append
7+
8+
# Get username/password & machine name
9+
$userName = "artifactInstaller"
10+
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
11+
$password = $([System.Web.Security.Membership]::GeneratePassword(12,4))
12+
$cn = [ADSI]"WinNT://$env:ComputerName"
13+
14+
# Create new user
15+
$user = $cn.Create("User", $userName)
16+
$user.SetPassword($password)
17+
$user.SetInfo()
18+
$user.description = "Choco artifact installer"
19+
$user.SetInfo()
20+
21+
# Add user to the Administrators group
22+
$group = [ADSI]"WinNT://$env:ComputerName/Administrators,group"
23+
$group.add("WinNT://$env:ComputerName/$userName")
24+
25+
# Create pwd and new $creds for remoting
26+
$secPassword = ConvertTo-SecureString $password -AsPlainText -Force
27+
$credential = New-Object System.Management.Automation.PSCredential("$env:COMPUTERNAME\$($username)", $secPassword)
28+
29+
# Ensure that current process can run scripts.
30+
#"Enabling remoting" | Out-File $LogFile -Append
31+
Enable-PSRemoting -Force -SkipNetworkProfileCheck
32+
33+
#"Changing ExecutionPolicy" | Out-File $LogFile -Append
34+
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
35+
36+
# Install Choco
37+
#"Installing Chocolatey" | Out-File $LogFile -Append
38+
$sb = { iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) }
39+
Invoke-Command -ScriptBlock $sb -ComputerName $env:COMPUTERNAME -Credential $credential | Out-Null
40+
41+
#"Disabling UAC" | Out-File $LogFile -Append
42+
$sb = { Set-ItemProperty -path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System -name EnableLua -value 0 }
43+
Invoke-Command -ScriptBlock $sb -ComputerName $env:COMPUTERNAME -Credential $credential
44+
45+
#"Install each Chocolatey Package"
46+
$chocoPackages.Split(";") | ForEach {
47+
$command = "cinst " + $_ + " -y -force"
48+
$command | Out-File $LogFile -Append
49+
$sb = [scriptblock]::Create("$command")
50+
51+
# Use the current user profile
52+
Invoke-Command -ScriptBlock $sb -ArgumentList $chocoPackages -ComputerName $env:COMPUTERNAME -Credential $credential | Out-Null
53+
}
54+
55+
Disable-PSRemoting -Force
56+
57+
# Delete the artifactInstaller user
58+
$cn.Delete("User", $userName)
59+
60+
# Delete the artifactInstaller user profile
61+
gwmi win32_userprofile | where { $_.LocalPath -like "*$userName*" } | foreach { $_.Delete() }
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
{
2+
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.1",
4+
"parameters": {
5+
"storageType": {
6+
"type": "string",
7+
"defaultValue": "Premium_LRS",
8+
"allowedValues": [
9+
"Premium_LRS",
10+
"Standard_LRS"
11+
],
12+
"metadata": {
13+
"description": "Which type of storage you want to use"
14+
}
15+
},
16+
"vmName": {
17+
"type": "string",
18+
"metadata": {
19+
"description": "Local name for the VM can be whatever you want"
20+
}
21+
},
22+
"vmAdminUserName": {
23+
"type": "string",
24+
"metadata": {
25+
"description": "VM admin user name"
26+
}
27+
},
28+
"vmAdminPassword": {
29+
"type": "securestring",
30+
"metadata": {
31+
"description": "VM admin password. The supplied password must be between 8-123 characters long and must satisfy at least 3 of password complexity requirements from the following: 1) Contains an uppercase character 2) Contains a lowercase character 3) Contains a numeric digit 4) Contains a special character."
32+
}
33+
},
34+
"vmSize": {
35+
"type": "string",
36+
"metadata": {
37+
"description": "Desired Size of the VM. Any valid option accepted but if you choose premium storage type you must choose a DS class VM size."
38+
},
39+
"defaultValue": "Standard_DS2"
40+
},
41+
"vmVisualStudioVersion": {
42+
"type": "string",
43+
"defaultValue": "VS-2015-Ent-VSU2-AzureSDK-29-W10T-N-x64",
44+
"allowedValues": [
45+
"VS-2015-Comm-AzureSDK-2.9-W10T-Win10-N",
46+
"VS-2015-Comm-AzureSDK-2.9-WS2012R2",
47+
"VS-2015-Comm-VSU1-AzureSDK-2.8-W10T-N-x64",
48+
"VS-2015-Comm-VSU2-AzureSDK-29-W10T-N-x64",
49+
"VS-2015-Comm-VSU2-AzureSDK-29-WS2012R2",
50+
"VS-2015-Community-AzureSDK-2.7-Cordova-Win8.1-N-x64",
51+
"VS-2015-Community-AzureSDK-2.7-W10T-Win10-N",
52+
"VS-2015-Community-AzureSDK-2.7-WS2012R2",
53+
"VS-2015-Ent-AzureSDK-2.8-Cordova-Win8.1-N-x64",
54+
"VS-2015-Ent-AzureSDK-29-W10T-Win10-N",
55+
"VS-2015-Ent-VSU2-AzureSDK-29-W10T-N-x64",
56+
"VS-2015-Ent-VSU2-AzureSDK-29-WS2012R2",
57+
"VS-2015-Enterprise-AzureSDK-2.7-Cordova-Win8.1-N-x64",
58+
"VS-2015-Enterprise-AzureSDK-2.7-W10T-Win10-N",
59+
"VS-2015-Enterprise-AzureSDK-2.7-WS2012R2",
60+
"VS-2015-Pro-AzureSDK-2.8-Cordova-Win8.1-N-x64",
61+
"VS-2015-Professional-AzureSDK-2.7-Cordova-Win8.1-N-x64",
62+
"VS-2015-Professional-AzureSDK-2.7-W10T-Win10-N"
63+
],
64+
"metadata": {
65+
"description": "Which version of Visual Studio you would like to deploy"
66+
}
67+
},
68+
"dnsLabelPrefix": {
69+
"type": "string",
70+
"metadata": {
71+
"description": "DNS Label for the Public IP. Must be lowercase. It should match with the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$ or it will raise an error."
72+
}
73+
},
74+
"chocoPackages": {
75+
"type": "string",
76+
"metadata": {
77+
"description": "List of Chocolatey packages to install separated by a semi-colon eg. linqpad;sysinternals"
78+
}
79+
},
80+
"setupChocolateyScriptFileName": {
81+
"type": "string",
82+
"defaultValue": "SetupChocolatey.ps1",
83+
"metadata": {
84+
"description": "PowerShell script name to execute"
85+
}
86+
},
87+
"setupChocolatelyScriptLocation": {
88+
"type": "string",
89+
"defaultValue": "https://raw.githubusercontent.com/daltskin/ARMChocolatey/master/",
90+
"metadata": {
91+
"description": "Public uri location of PowerShell Chocolately setup script"
92+
}
93+
}
94+
},
95+
"variables": {
96+
"storageName": "[concat(uniquestring(resourceGroup().id), 'standardsa')]",
97+
"vnet01Prefix": "10.0.0.0/16",
98+
"vnet01Subnet1Name": "Subnet-1",
99+
"vnet01Subnet1Prefix": "10.0.0.0/24",
100+
"vmImagePublisher": "MicrosoftVisualStudio",
101+
"vmImageOffer": "VisualStudio",
102+
"vmOSDiskName": "VMOSDisk",
103+
"vmVnetID": "[resourceId('Microsoft.Network/virtualNetworks', 'Vnet01')]",
104+
"vmSubnetRef": "[concat(variables('VMVnetID'), '/subnets/', variables('Vnet01Subnet1Name'))]",
105+
"vmStorageAccountContainerName": "vhds",
106+
"vmNicName": "[concat(parameters('VMName'), 'NetworkInterface')]",
107+
"vmIP01Name": "VMIP01"
108+
},
109+
"resources": [
110+
{
111+
"name": "[variables('storageName')]",
112+
"type": "Microsoft.Storage/storageAccounts",
113+
"location": "[resourceGroup().location]",
114+
"apiVersion": "2015-06-15",
115+
"dependsOn": [ ],
116+
"tags": {
117+
"displayName": "Storage01"
118+
},
119+
"properties": {
120+
"accountType": "[parameters('storageType')]"
121+
}
122+
},
123+
{
124+
"name": "VNet01",
125+
"type": "Microsoft.Network/virtualNetworks",
126+
"location": "[resourceGroup().location]",
127+
"apiVersion": "2015-06-15",
128+
"dependsOn": [ ],
129+
"tags": {
130+
"displayName": "VNet01"
131+
},
132+
"properties": {
133+
"addressSpace": {
134+
"addressPrefixes": [
135+
"[variables('vnet01Prefix')]"
136+
]
137+
},
138+
"subnets": [
139+
{
140+
"name": "[variables('vnet01Subnet1Name')]",
141+
"properties": {
142+
"addressPrefix": "[variables('vnet01Subnet1Prefix')]"
143+
}
144+
}
145+
]
146+
}
147+
},
148+
{
149+
"name": "[variables('vmNicName')]",
150+
"type": "Microsoft.Network/networkInterfaces",
151+
"location": "[resourceGroup().location]",
152+
"apiVersion": "2015-06-15",
153+
"dependsOn": [
154+
"[concat('Microsoft.Network/virtualNetworks/', 'Vnet01')]",
155+
"[concat('Microsoft.Network/publicIPAddresses/', variables('vmIP01Name'))]"
156+
],
157+
"tags": {
158+
"displayName": "VMNic01"
159+
},
160+
"properties": {
161+
"ipConfigurations": [
162+
{
163+
"name": "ipconfig1",
164+
"properties": {
165+
"privateIPAllocationMethod": "Dynamic",
166+
"subnet": {
167+
"id": "[variables('vmSubnetRef')]"
168+
},
169+
"publicIPAddress": {
170+
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('vmIP01Name'))]"
171+
}
172+
}
173+
}
174+
]
175+
}
176+
},
177+
{
178+
"name": "[parameters('vmName')]",
179+
"type": "Microsoft.Compute/virtualMachines",
180+
"location": "[resourceGroup().location]",
181+
"apiVersion": "2015-06-15",
182+
"dependsOn": [
183+
"[concat('Microsoft.Storage/storageAccounts/', variables('storageName'))]",
184+
"[concat('Microsoft.Network/networkInterfaces/', variables('vmNicName'))]"
185+
],
186+
"tags": {
187+
"displayName": "VM01"
188+
},
189+
"properties": {
190+
"hardwareProfile": {
191+
"vmSize": "[parameters('vmSize')]"
192+
},
193+
"osProfile": {
194+
"computername": "[parameters('vmName')]",
195+
"adminUsername": "[parameters('vmAdminUsername')]",
196+
"adminPassword": "[parameters('vmAdminPassword')]"
197+
},
198+
"storageProfile": {
199+
"imageReference": {
200+
"publisher": "[variables('vmImagePublisher')]",
201+
"offer": "[variables('vmImageOffer')]",
202+
"sku": "[parameters('vmVisualStudioVersion')]",
203+
"version": "latest"
204+
},
205+
"osDisk": {
206+
"name": "VMOSDisk",
207+
"vhd": {
208+
"uri": "[concat('http://', variables('storageName'), '.blob.core.windows.net/', variables('vmStorageAccountContainerName'), '/', variables('vmOSDiskName'), '.vhd')]"
209+
},
210+
"caching": "ReadWrite",
211+
"createOption": "FromImage"
212+
}
213+
},
214+
"networkProfile": {
215+
"networkInterfaces": [
216+
{
217+
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('vmNicName'))]"
218+
}
219+
]
220+
}
221+
},
222+
"resources": [
223+
{
224+
"name": "SetupChocolatey",
225+
"type": "extensions",
226+
"location": "[resourceGroup().location]",
227+
"apiVersion": "2015-06-15",
228+
"dependsOn": [
229+
"[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
230+
],
231+
"tags": {
232+
"displayName": "SetupChocolatey"
233+
},
234+
"properties": {
235+
"publisher": "Microsoft.Compute",
236+
"type": "CustomScriptExtension",
237+
"typeHandlerVersion": "1.4",
238+
"autoUpgradeMinorVersion": true,
239+
"settings": {
240+
"fileUris": [
241+
"[concat(parameters('setupChocolatelyScriptLocation'),parameters('setupChocolateyScriptFileName'))]"
242+
],
243+
"commandToExecute": "[concat('powershell -ExecutionPolicy bypass -File ',parameters('setupChocolateyScriptFileName'),' -chocoPackages ',parameters('chocoPackages'))]"
244+
}
245+
}
246+
}
247+
]
248+
},
249+
{
250+
"name": "[variables('vmIP01Name')]",
251+
"type": "Microsoft.Network/publicIPAddresses",
252+
"location": "[resourceGroup().location]",
253+
"apiVersion": "2015-06-15",
254+
"dependsOn": [ ],
255+
"tags": {
256+
"displayName": "VMIP01"
257+
},
258+
"properties": {
259+
"publicIPAllocationMethod": "Dynamic",
260+
"dnsSettings": {
261+
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
262+
}
263+
}
264+
}
265+
],
266+
"outputs": { }
267+
}
268+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"vmIPPublicDnsName": {
6+
"value": "GEN-UNIQUE-13"
7+
},
8+
"storageType": {
9+
"value": "Premium_LRS"
10+
},
11+
"deployLocation": {
12+
"value": "West Europe"
13+
},
14+
"vmName": {
15+
"value": "VSVM"
16+
},
17+
"vmAdminUserName": {
18+
"value": "YourAdminName"
19+
},
20+
"vmAdminPassword": {
21+
"value": "GEN-PASSWORD"
22+
},
23+
"vmSize": {
24+
"value": "Standard_DS2"
25+
},
26+
"vmVisualStudioVersion": {
27+
"value": "VS-2015-Ent-VSU2-AzureSDK-29-W10T-N-x64"
28+
},
29+
"chocoPackages": {
30+
"value": "sysinternals"
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)