Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zandercodes/f00b21ec0c6ce7e917b603ed1aae0331 to your computer and use it in GitHub Desktop.
Save zandercodes/f00b21ec0c6ce7e917b603ed1aae0331 to your computer and use it in GitHub Desktop.
Ensure script runs under PowerShell 7.5 or higher
# Ensure script runs under PowerShell 7.5 or higher
if ($PSVersionTable.PSVersion -lt [Version]"7.5") {
$pwshExe = Get-Command pwsh.exe -ErrorAction SilentlyContinue
if ($pwshExe -and $pwshExe.Version -ge [Version]"7.5") {
Write-Host "Restarting script with PowerShell 7.5 or higher..."
& $pwshExe.Source -File $MyInvocation.MyCommand.Path @args
exit
} else {
Write-Host "This script requires PowerShell 7.5 or higher."
exit 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment