Created
March 12, 2019 06:56
-
-
Save clong/7384ef9dae148eb7bdce346f4f83b906 to your computer and use it in GitHub Desktop.
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
# This script downloads an updated Caldera config if the one in replace | |
# is found to not match the one on the server | |
$tempCalderaCertFromServer = "c:\windows\temp\conf.yml" | |
$cagentConfPath = "C:\Program Files\cagent\conf.yml" | |
try { | |
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;(New-Object System.Net.WebClient).DownloadFile('https://logger:8888/conf.yml', $tempCalderaCertFromServer) | |
} catch { | |
Write-Host "The Caldera server cannot be reached at this time." | |
exit | |
} | |
if (Test-Path $tempCalderaCertFromServer) { | |
$diff = compare-object (get-content "$cagentConfPath") (get-content "$tempCalderaCertFromServer") | |
# If the files differ, move the most recently downloaded conf file into place and restart the service | |
# After this is done, we can simply disable the scheduled task | |
if ($diff) { | |
Copy-Item $tempCalderaCertFromServer $cagentConfPath -Force | |
Restart-Service -name cagent | |
Disable-ScheduledTask -TaskName "Caldera_Config_Fixer" | |
} else { | |
Disable-ScheduledTask -TaskName "Caldera_Config_Fixer" | |
} | |
} | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment