Skip to content

Instantly share code, notes, and snippets.

@fatihtatoglu
Last active April 7, 2021 09:28
Show Gist options
  • Save fatihtatoglu/28477fdcfda549fae5f1e3403c9faa4f to your computer and use it in GitHub Desktop.
Save fatihtatoglu/28477fdcfda549fae5f1e3403c9faa4f to your computer and use it in GitHub Desktop.
$currentVersion = $PSVersionTable.PSVersion.Major
if ($currentVersion -ge 5) {
Write-Host "PowerShell is updated."
return
}
$url = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Upgrade-PowerShell.ps1"
$file = "$env:temp\Upgrade-PowerShell.ps1"
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
Write-Host "Update script is downloaded."
$currentPolicy = Get-ExecutionPolicy -List | Where-Object Scope -eq "LocalMachine" | Select-Object ExecutionPolicy
if ($currentPolicy -ne "Unrestricted") {
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
}
&$file -Version 5.1 -Verbose
Set-ExecutionPolicy -ExecutionPolicy $currentPolicy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment