PowerShell Location
-
Use
Host.version
to Find the Location of thePowerShell.exe
in Windows Server 2008 -
Get-Process
to Find the Location of thePowerShell.exe
in Windows Server 2008
PowerShell is a Command-line interface for Scripting purposes, automation requirements, and CI/CD systems management installed by default in every Windows PC, starting with Windows 7.
It is used to bridge this gap between Windows users and users of Linux-like systems.
This article is mainly about finding the PowerShell.exe
file location in different ways.
The focus group of users of the provided solution would be Windows Server 2008 users. Yet, it applies to users from Windows 7 Version upwards.
Use Host.version
to Find the Location of the PowerShell.exe
in Windows Server 2008
When you use a version of Windows PowerShell newer to Version 1.0, you will have difficulty finding the correct pathway to Windows PowerShell. In my case, I have PowerShell version 5 installed on my Windows 10 PC.
Yet when the command to open the directory in Windows PowerShell dir
is run, the shown version is v1.0.
PS C:\Windows\System32\WindowsPowerShell> dir
Output:
Directory: C:\Windows\System32\WindowsPowerShell
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 4/9/2021 7:23 PM v1.0
Here what happens is confusion caused due to directory naming by Microsoft.
It shows Length Name as v1.0, but this is not my PC’s actual version name of the PowerShell application. Therefore, We will use the $Host.version
command to find the correct version of PowerShell.
PS C:\Windows\System32\WindowsPowerShell> $Host.version
The output of this code shows the correct major and minor versions of PowerShell.
PS C:\Windows\System32\WindowsPowerShell> $Host.version
Major Minor Build Revision
---- - ---- - ---- - --------
5 1 19041 1320
As you can see, the version is Windows PowerShell 5.1, not Version v1.0.
This confusion is caused because developers were updating the version. However, the file folder name remains the same as v1.0. Inside the v1.0 folder directory, you can see the .exe
file of Windows PowerShell 5.1.
If you find the correct location, you have to go inside the v1.0 folder and get the .exe
file. To find the right version information, you need to execute PowerShell’s $Host.version
command.
Get-Process
to Find the Location of the PowerShell.exe
in Windows Server 2008
A convenient way of finding the location pathway of the PowerShell.exe
file in Windows PC is through the Get-Process
command.
You do not need to direct to the PowerShell folder to run the commands. Below is the command that would directly show the path of the PowerShell.exe
file.
PS C:\Users\Agni> (Get-Process powershell | select -First 1).Path
Output:
PS C:\Users\Agni> (Get-Process powershell | select -First 1).Path
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Hence, this method can be identified as the hassle-free way to determine the correct pathway to the required .exe
file. Yet, you cannot identify the version of your PowerShell as we did in the previous method.
Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.