Last active
August 29, 2015 14:15
-
-
Save petems/738ee9c930efc0f2d43e to your computer and use it in GitHub Desktop.
Change Puppet Enterprise Interval Checkin on Windows to 30s
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
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" | |
} | |
} | |
$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