Use PowerShell 2 with .NET Framework 2.0
Last updated
Last updated
PowerShell 2 uses .NET Framework's 2.0 by default.
If you use PowerShell 2 and try to import the a module (such as VisioPS) which requires .NET Framework 4.0, you'll get an error like this:
To see what versions any version of Powershell is using, look at $PSVersionTable
. For example, below is an example of $PSVersionTable
from a Windows 7 machine running Powershell. The CLRVersion
indicates which version of the .NET Framework is used and in this case it begins with "2".
VisioPS requires a .NET Framework 4.0.
Notice the value or CLRVersion begins with a "2".
In any case, this is a common occurrence with a straightforward solution. You can force PowerShell to start using the .NET Framework 4.0 . The procedure involves creating two small XML files and placing them in the appropriate place.
Here is a small PowerShell script that will automatically create and place the necessary files. Be aware that the script as shown below will overwrite existing .config files.
$config_text = @" <?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0.30319"/> <supportedRuntime version="v2.0.50727"/> </startup> </configuration> "@
$config_text| Out-File $pshome\powershell.exe.config $config_text| Out-File $pshome\powershell_ise.exe.config
Start PowerShell as an Administrator an then run the script. Then restart PowerShell and examine the value of $PSVersionTable
. The value or CLRVersion
now begins with a "4". Now your can load VisioPS or any other .NET 4.0 module correctly.