Skip to content

Instantly share code, notes, and snippets.

@ipcrm
Created June 7, 2016 15:52
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipcrm/90579fdf89865610ca59f2906f3ab656 to your computer and use it in GitHub Desktop.
Save ipcrm/90579fdf89865610ca59f2906f3ab656 to your computer and use it in GitHub Desktop.
Install Puppet using Powershell
# This script installs the windows puppet agent on windows
# from the master's pe_repo by downloading it to C:\tmp first and then running
# msiexec on it from there.
$puppet_master_server = "master.example.com"
$msi_source = "https://${puppet_master_server}:8140/packages/current/windows-x86_64/puppet-agent-x64.msi"
$msi_dest = "C:\tmp\puppet-agent-x64.msi"
# Start the agent installation process and wait for it to end before continuing.
Write-Host "Installing puppet agent from $msi_source"
# Determine system hostname and primary DNS suffix to determine certname
$objIPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
$name_components = @($objIPProperties.HostName, $objIPProperties.DomainName) | ? {$_}
$certname = $name_components -Join "."
Function Get-WebPage { Param( $url, $file, [switch]$force)
if($force) {
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
}
$webclient = New-Object system.net.webclient
$webclient.DownloadFile($url,$file)
}
Get-WebPage -url $msi_source -file $msi_dest -force
$msiexec_path = "C:\Windows\System32\msiexec.exe"
$msiexec_args = "/qn /log c:\log.txt /i $msi_dest PUPPET_MASTER_SERVER=$puppet_master_server PUPPET_AGENT_CERTNAME=$certname"
$msiexec_proc = [System.Diagnostics.Process]::Start($msiexec_path, $msiexec_args)
$msiexec_proc.WaitForExit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment