-
Notifications
You must be signed in to change notification settings - Fork 186
/
windows.ps1
67 lines (55 loc) · 2.26 KB
/
windows.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
<#
.SYNOPSIS
Installs Puppet on this machine.
.DESCRIPTION
Downloads and installs the PuppetLabs Puppet MSI package.
This script requires administrative privileges.
You can run this script from an old-style cmd.exe prompt using the
following:
powershell.exe -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "& '.\windows.ps1'"
.PARAMETER MsiUrl
This is the URL to the Puppet MSI file you want to install. This defaults
to a version from PuppetLabs.
.PARAMETER PuppetVersion
This is the version of Puppet that you want to install. If you pass this it will override the version in the MsiUrl.
This defaults to $null.
#>
param(
[string]$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-3.3.2.msi"
,[string]$PuppetVersion = $null
)
if ($PuppetVersion) {
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-$($PuppetVersion).msi"
Write-Host "Puppet version $PuppetVersion specified, updated MsiUrl to `"$MsiUrl`""
}
$PuppetInstalled = $false
try {
$ErrorActionPreference = "Stop";
Get-Command puppet | Out-Null
$PuppetInstalled = $true
$PuppetVersion=&puppet "--version"
Write-Host "Puppet $PuppetVersion is installed. This process does not ensure the exact version or at least version specified, but only that puppet is installed. Exiting..."
Exit 0
} catch {
Write-Host "Puppet is not installed, continuing..."
}
if (!($PuppetInstalled)) {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (! ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
Write-Host -ForegroundColor Red "You must run this script as an administrator."
Exit 1
}
# Install it - msiexec will download from the url
$install_args = @("/qn", "/norestart","/i", $MsiUrl)
Write-Host "Installing Puppet. Running msiexec.exe $install_args"
$process = Start-Process -FilePath msiexec.exe -ArgumentList $install_args -Wait -PassThru
if ($process.ExitCode -ne 0) {
Write-Host "Installer failed."
Exit 1
}
# Stop the service that it autostarts
Write-Host "Stopping Puppet service that is running by default..."
Start-Sleep -s 5
Stop-Service -Name puppet
Write-Host "Puppet successfully installed."
}