Who’s Driving this Shell?

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.

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.

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.

2017-08-08_10-29-38

image

image

image

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.

Leave a Reply

Your email address will not be published. Required fields are marked *