Microsoft has been busy with the next iteration of PowerShell. As you should already know, this version will run cross-platform. The executable, or engine, is naturally different than what you are used to with Windows PowerShell. As I was trying out the latest PowerShell beta, I needed to identify the path to the current PowerShell engine. I then thought it might be helpful to get even more details so I put together a quick PowerShell function called Get-PowerShellEngine.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Getting the current PowerShell engine is pretty easy because we can use the built-in $pid variable which references the process ID for the current PowerShell session.
Get-Process -id $pid | Select -ExpandProperty Path
You can try that out in any PowerShell session and you should get a path like C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe or C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell_ise.exe. But since I always want more, I decided to grab some additional properties from $PSVersionTable and $Host. The complete function is a gist on GitHub.
The default behavior is to return the path. But using the –Detail parameter writes a custom object to the pipeline.I had a lot of fun trying out in different PowerShell sessions.
As you can see from the screen shots, not all properties may have a value depending on your operating system or hosting application. But this could change as the PowerShell betas advance and when we ultimately reach RTM. I hope you’ll give this a spin and let me know what you think. If you encounter problems, please post an issue on the gist page.