-
Notifications
You must be signed in to change notification settings - Fork 2
/
vagrant_provisionWin2012.ps1
138 lines (113 loc) · 4.69 KB
/
vagrant_provisionWin2012.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# provision.ps1
# Author: Michelangelo Bottura
#
#
# Funzioni
Function Test-Command
{
[CmdletBinding()]
[OutputType([bool])]
Param (
[string]$command = 'choco'
)
Write-Verbose -Message "Test-Command $command"
if (Get-Command -Name $command -ErrorAction SilentlyContinue) {
Write-Verbose -Message "$command exists"
return $true
} else {
Write-Verbose -Message "$command does NOT exist"
return $false
}
}
Function Install-Choco {
$mytest = test-command -command "choco.exe"
switch ( $mytest ) {
$true {
write-verbose "Installazione di choco non necessaria"
}
$false {
write-host "Avvio Installazione choco"
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Continue
#Set-ExecutionPolicy RemoteSigned; $ERRORACTION=continue;
}
Default { Write-Error "stato non determinato"}
}
}
# variabili
$setupDir = Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
Push-Location $setupDir
[Environment]::CurrentDirectory = $PWD
$kms = "kms-svr.dir.unibo.it"
$slmgr = "\windows\system32\slmgr.vbs"
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
$KmsSetupKey = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"
#if (-not(Get-ItemProperty $path)."KeyManagementServiceName") {
# Write-Host "Setting KMS server..."
# $proc = Start-Process "cscript.exe" -Wait -PassThru -NoNewWindow -ArgumentList @("/nologo", $slmgr, "-skms", $kms)
# if ($proc.ExitCode -ne 0) {
# Throw "set KMS server failed"
# }
#}
If (-not(Get-ItemProperty $path)."IsActivated") {
Write-Host "Impostazione KMS cleint key..."
$proc = Start-Process "cscript.exe" -wait -PassThru -NoNewWindow -ArgumentList @("/nologo", $slmgr, "-ipk ", $KmsSetupKey)
# mostra errore slui.exe 0x2a 0xc004d302
If ($proc.ExitCode -ne 0) {
#Throw "setup KMS client key failed"
write-warning "Impostazione KMS client key fallita, tentativo attivazione con key presente"
}
$proc = Start-Process "cscript.exe" -Wait -PassThru -NoNewWindow -ArgumentList @("/nologo", $slmgr, "-ato")
If ($proc.ExitCode -ne 0) {
#Throw "activate via KMS failed"
write-warning "Attivazione via KMS fallita, esecuzione rearm"
$proc = Start-Process "cscript.exe" -Wait -PassThru -NoNewWindow -ArgumentList @("/nologo", $slmgr, "-rearm")
}
Set-ItemProperty -Path $path -Name "IsActivated" -Value 1
}
Write-Host "Disabilitazione modalita' protetta per IE (user & admin)"
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0
Write-Host -fore red "Disabilitazione Windows Firewall - disattivare se necessario"
Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled False
Write-host "Impostazione Tastiera Italiana"
set-WinUserLanguageList -LanguageList it-IT -Confirm:$false -Force
Write-Host "Impostazione TimeZone"
tzutil /s "W. Europe Standard Time"
Write-Host "Installazione chocolatey"
do { write-host "Installazione Chocolatey..."
Install-Choco
sleep 10
} while ( -not $(test-command -command "choco.exe") )
Write-host "Elimina la conferma di installazione"
choco feature enable -n allowGlobalConfirmation
Write-Host "Installazione/aggiornamento WMF 5.1 -> DSC"
choco install powershell #--force
Write-host "Installazione puppet agent"
choco install puppet-agent
Write-Host "Creazione dir per ambiente dev"
$devPath = "C:\ProgramData\PuppetLabs\code\environments\dev"
while ( -not (Test-Path $devPath) ) {
write-host "path non esistente, creo"
new-item $devPath -ItemType Directory -Force # | out-null
}
# Creazione Shortcut per test puppet (powershell 5.0 è disponibile solo dopo riavvio )
# New-Item -ItemType SymbolicLink -Path "$env:userprofile\Desktop\" -Name "Puppet-Code DEV" -Value "C:\vagrant\Puppet-Code\environments\dev"
$wshshell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop')
$lnk = $wshshell.CreateShortcut($desktop+"\Puppet-Code DEV.lnk")
$lnk.TargetPath = "C:\vagrant\Puppet-Code\environments\dev"
$lnk.Save()
Write-Host "Riavvio necessario"
shutdown -t 10 -r -f
# Valutare:
# set WSUS
## registry
## install nuget
# Install-packageprovider -name nuget -force
## install module pswindowsupdate
# Install-Module -Name PSWindowsUpdate -force
## Install updates
# get-WUinstall
Write-Host "Provisioning Terminato"