Created
February 11, 2015 15:10
-
-
Save petems/c0d49d253620479751bb to your computer and use it in GitHub Desktop.
AWS Windows Bootstrap
This file contains hidden or 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
Set-ExecutionPolicy Unrestricted -Force | |
function Start-ProcessAsAdmin( | |
[string] $FilePath, | |
[string] $Arguments) | |
{ | |
if ($FilePath -match ".*powershell") | |
{ | |
$Arguments = "-NoProfile -ExecutionPolicy Unrestricted -Command `"$Arguments`"" | |
} | |
$process = New-Object System.Diagnostics.Process | |
$process.StartInfo.Filename = $FilePath | |
$process.StartInfo.Arguments = $Arguments | |
$process.StartInfo.RedirectStandardOutput = $true | |
$process.StartInfo.RedirectStandardError = $true | |
$process.StartInfo.UseShellExecute = $false | |
if(([System.Security.Principal.WindowsPrincipal][System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) | |
{ | |
Write-Verbose "Running in elevated process" | |
$process.StartInfo.Verb = 'runAs' | |
} | |
else | |
{ | |
Write-Verbose "Running in an already elevated process" | |
} | |
if ($process.Start()) | |
{ | |
$process.WaitForExit() | |
[string] $err = $process.StandardError.ReadToEnd() | |
if ( $err -ne "" ) | |
{ | |
throw $err | |
} | |
[string] $out = $process.StandardOutput.ReadToEnd() | |
$out | |
} | |
else | |
{ | |
Write-Error "Cannot start process" | |
} | |
} | |
Write-Output "Installing MSI" | |
$msiExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList "/qn /i https://s3.amazonaws.com/pe-builds/released/3.3.2/puppet-enterprise-3.3.2.msi PUPPET_MASTER_SERVER=1.1.1.1 PUPPET_AGENT_CERTNAME=coolcertname" -Wait -Passthru).ExitCode | |
Write-Output "Puppet Agent MSI installer returned exit code $msiExitCode" | |
if ($msiExitCode -ne 0) { | |
throw "Installation aborted" | |
} | |
$PuppetConfig = 'C:/ProgramData/PuppetLabs/puppet/etc/puppet.conf' | |
Start-ProcessAsAdmin powershell "Stop-Service pe-puppet" | |
$process = Start-ProcessAsAdmin powershell "Add-Content $PuppetConfig '`n runinterval = 30' -Force" | |
Start-ProcessAsAdmin powershell "Set-Service pe-puppet -StartupType Automatic -Status Running" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment