Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active December 29, 2015 07:58
Show Gist options
  • Save grenade/7639518 to your computer and use it in GitHub Desktop.
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.
$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