PowerShell 2 and .NET Framework 4

By default PowerShell 2 is using .NET CLR 2.0.

It is quite annoying. I would like to be able to use something like
[string]::IsNullOrWhitespace from .NET Framework 4

There are several approaches

1. Modify .NET settings globally saying to use only latest .NET CLR version

Windows Registry Editor Version 5.00



2. Modify or create the files powershell.exe.config and powershell_ise.exe.config in $PSHOME folder

<?xml version="1.0"?> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0.30319"/> 
        <supportedRuntime version="v2.0.50727"/> 

To check what you have use

# Current PowerShell version

# Current .NET Framework version

Unfortunately both of these approaches did not work well if you have PowerShell 3 installed.

If you run PowerShell.exe -Version 2 it will run PowerShell version 2 with .NET version 2
If you use one of the approached shown above

$host.Version is always 3 even if you ran PowerShell.exe -Version 2.

EDIT: Raised a bug https://connect.microsoft.com/PowerShell/feedback/details/767907/powershell-2-0-with-net-4-0-on-windows-8


About mnaoumov

Senior .NET Developer in Readify
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s