Created
January 21, 2019 11:29
-
-
Save nitsh/b94240b97e4cfbb80f39908dc7818951 to your computer and use it in GitHub Desktop.
Install puppet in windows with powershell
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
#https://github.com/ferventcoder/vagrant-windows-puppet/blob/master/boxes/shared/shell/InstallPuppetFromMSI.ps1 | |
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-3.7.3.msi" | |
$PuppetInstallerPath = 'c:\vagrant\bin' | |
$PuppetInstallerFile = 'puppet.msi' | |
$PuppetInstaller = Join-Path $PuppetInstallerPath $PuppetInstallerFile | |
if ([System.IntPtr]::Size -eq 8) { | |
Write-Host "Going to Puppet 64-bit." | |
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-3.7.3-x64.msi" | |
$PuppetInstallerFile = 'puppet-x64.msi' | |
} | |
$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 | |
} | |
if (!(Test-Path $PuppetInstallerPath)) { | |
Write-Host "Creating folder `'$PuppetInstallerPath`'" | |
$null = New-Item -Path "$PuppetInstallerPath" -ItemType Directory | |
} | |
if (!(Test-Path $PuppetInstaller)) { | |
Write-Host "Downloading `'$MsiUrl`' to `'$PuppetInstaller`'" | |
(New-Object Net.WebClient).DownloadFile("$MsiUrl","$PuppetInstaller") | |
} | |
# Install it - msiexec will download from the url | |
$install_args = @("/qn", "/norestart","/i", "$PuppetInstaller") | |
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 | |
} | |
Write-Host "Puppet successfully installed." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment