Last active
December 29, 2015 07:58
-
-
Save grenade/7639518 to your computer and use it in GitHub Desktop.
Adds support for .Net runtime 4 in PowerShell by creating a powershell.exe.config file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | |
| $windowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($windowsIdentity) | |
| $adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator | |
| if (!($windowsPrincipal.IsInRole($adminRole))) { | |
| $psi = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; | |
| $psi.Arguments = $myInvocation.MyCommand.Definition; | |
| $psi.Verb = "runas"; | |
| [System.Diagnostics.Process]::Start($psi); | |
| exit | |
| } | |
| $psconfig = "{0}\powershell.exe.config" -f $pshome | |
| if(!(Test-Path -Path ($psconfig))) | |
| { | |
| $config = | |
| @" | |
| <?xml version="1.0"?> | |
| <configuration> | |
| <startup useLegacyV2RuntimeActivationPolicy="true"> | |
| <supportedRuntime version="v4.0.30319"/> | |
| <supportedRuntime version="v2.0.50727"/> | |
| </startup> | |
| </configuration> | |
| "@ | |
| New-Item -Path $psconfig –type file -value ($config) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment