PS: PowerShell Version Verification

PS: PowerShell Version Verification

I have made the following below to validate the version of powershell that is currently running on the machine and if the version is incorrect to print and error and close the script. Pretty handy snippet to put at the start of your script

if ($PSVersionTable.PSVersion.Major -gt 2)
{
Write-host 'Current System Powershell Version Meets Script Requirements'
}
else
{
Write-host 'Current System Powershell Version does not meet requirements' -ForegroundColor Red
Write-host 'Please Update your Powershell Version to 2.0 or greater' -ForegroundColor Red
write-host 'Script has stopped' -ForegroundColor Red
exit
}
Advertisements