Skip to content

Instantly share code, notes, and snippets.

@echohack
Last active August 23, 2016 20:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save echohack/932b51cf190c70be7379 to your computer and use it in GitHub Desktop.
Save echohack/932b51cf190c70be7379 to your computer and use it in GitHub Desktop.
chef_windows_upgrade.ps1
# Execute this script in order to upgrade all the windows nodes in your fleet of servers to the desired version of chef-client.
# This script will requires the ChefDK to be installed and configured on your Windows machine.
$windows_nodes = knife search node 'platform:windows' -i
invoke-command -ComputerName $windows_nodes -filepath C:\Users\MyUser\invoke_upgrade.ps1 -Credential domain\user
Read-Host -Prompt “Upgrade complete. Press Enter to exit.”
$chef_version = chef-client -v
$upgrade_version = '12.5.1'
$computername = (Get-Childitem env:computername).Value
If (-Not ($chef_version -like "*$upgrade_version*"))
{
Write-Host "Upgrading $computername to $upgrade_version"
$source = "https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-$upgrade_version-1.msi"
$destination = "C:\chef\cache\chef-client-$upgrade_version-1.msi"
Invoke-WebRequest $source -OutFile $destination
Start-Process msiexec -ArgumentList "/qn /i $destination ADDLOCAL=ALL" -Wait -PassThru
Remove-Item $destination
}
else
{
Write-Host "$computername is already at $chef_version."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment