Question

Some folks who use PowerShell version 3.0 or 4.0 know that you can specify the -Version 2.0 parameter to launch PowerShell version 2.0. I became curious to know where exactly the PowerShell v2.0 executable resided, so I decided to do some research.

PowerShell 4.0

powershell.exe
$PSVersionTable.PSVersion;
(Get-Process -Id $pid).Path;

PowerShell 2.0

And then for PowerShell version 2.0, the same thing:

powershell -version 2.0
$PSVersionTable.PSVersion;
(Get-Process -Id $pid).Path;

The results show that the two PowerShell versions are running from the same file path, but the two processes are running different CLR versions.

My question is: How can this situation be possible, where the same .NET assembly is executing in two different CLR versions?

PowerShell Versions PowerShell CLR Version

Was it helpful?

Solution

The answer, it turns out, is quite simple: PowerShell.exe is not a .NET Assembly (had to verify with ILDasm.exe to prove it to myself).

It simply loads modules/dlls into the CLR as needed. The CLRVersion value is reporting the CLR version that PowerShell will use when it loads assemblies. Unfortunately I'm not able to find any good resources that detail the process PowerShell uses to load/interact with .NET code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top