Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download and install salt-minion on windows
function Install-SaltClient(){
$FolderPath = "C:\ProgramData\SaltClient"
$FileName = "Salt-Minion-3004-2-Py3-AMD64.msi"
$Installer = $FolderPath + "\" + $FileName
$URL = "https://mywebserver.example.com/public/" + $FileName
$Hash = "11DE07BA38CA2B65B168237CA2485B1983A151528242C7BF81EC04A94660C0E8"
$SaltMaster = "mysaltmaster.example.com"
# Make Folder for tracking install
if(-not (Test-Path $FolderPath)){
mkdir $FolderPath
}
# Already attempted
if(Test-Path ($FolderPath + "\Attempted.txt")){
return
}
$HashCheck = $False
# We cannot check the file hash
if(Get-Command "Get-FileHash" -EA SilentlyContinue){
$HashCheck = $True
}
# Download installer
(New-Object System.Net.WebClient).DownloadFile($URL, $Installer)
# Download failed, bail
if(
$HashCheck -and
((Get-FileHash -Algorithm SHA256 $Installer).Hash -ne $Hash)
){
return
}
& msiexec /i $Installer /quiet /norestart MASTER=$SaltMaster
# touch a file so we don't run again
"" | Out-File -Encoding Default ($FolderPath + "\Attempted.txt")
}
Install-SaltClient
@nickadam
Copy link
Author

nickadam commented Dec 19, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment