MyITGuy
5/19/2014 - 9:36 PM

Force Powershell to use a specific version.

Force Powershell to use a specific version.

#Check to see if running Version 2.0, if not re-run the script with the given parameters in Version 2.0
If ($host.version -ne "2.0") {
    $params = ($PSBoundParameters.GetEnumerator() | % {"-{0} {1}" -f $_.Key,$_.Value}) -join " "
    Start-Process -File PowerShell.exe -Argument "-Version 2 -noprofile -noexit -file $($myinvocation.mycommand.definition) $params"
    Break
}

# Check to see if running Version 3.0
If ($host.Version.ToString() -lt "3.0") {
	$host.Version.ToString()
    Break
}