Powershell.exe 的路径(v 2.0)

发布于 2024-10-01 09:43:04 字数 591 浏览 0 评论 0原文

Powershell(2.0 版)位于哪里? Powershell.exe 的路径是什么?我安装了 Windows Server 2008 和 Powershell。当我查看此文件夹时:

PS C:\Windows\System32\WindowsPowerShell> dir


    Directory: C:\Windows\System32\WindowsPowerShell


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         20.4.2010     17:09            v1.0

我只有 Powershell v1.0。但是当我输入时

PS C:\> $Host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1


PS C:\>

它显示我已经安装了 v2.0。

Where is the Powershell (version 2.0) located? What is the path to Powershell.exe? I have Windows Server 2008 and Powershell installed. When I look at this folder:

PS C:\Windows\System32\WindowsPowerShell> dir


    Directory: C:\Windows\System32\WindowsPowerShell


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         20.4.2010     17:09            v1.0

I have only Powershell v1.0. But when I type

PS C:\> $Host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1


PS C:\>

It shows that I have v2.0 installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

萌酱 2024-10-08 09:43:04

我相信它位于 C:\Windows\System32\WindowsPowershell\v1.0\ 中。为了迷惑无辜者,MS 将其保存在标有“v1.0”的目录中。在 Windows 7 上运行此程序并通过 $Host.Version 检查版本号 (确定安装的 PowerShell 版本)显示它是 2.0。

另一个选项是在命令提示符下键入 $PSVersionTable。如果您运行的是 v2.0,则输出将为:

Name                           Value
----                           -----
CLRVersion                     2.0.50727.4927
BuildVersion                   6.1.7600.16385
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

如果您运行的是 1.0 版本,则该变量不存在,并且不会有输出。

本地化 PowerShell 版本 1.0、2.0、3.0、4.0:

  • 64 位版本:C:\Windows\System32\WindowsPowerShell\v1.0\
  • 32 位版本:C:\Windows\SysWOW64\WindowsPowerShell\v1.0\

I believe it's in C:\Windows\System32\WindowsPowershell\v1.0\. In order to confuse the innocent, MS kept it in a directory labeled "v1.0". Running this on Windows 7 and checking the version number via $Host.Version (Determine installed PowerShell version) shows it's 2.0.

Another option is type $PSVersionTable at the command prompt. If you are running v2.0, the output will be:

Name                           Value
----                           -----
CLRVersion                     2.0.50727.4927
BuildVersion                   6.1.7600.16385
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

If you're running version 1.0, the variable doesn't exist and there will be no output.

Localization PowerShell version 1.0, 2.0, 3.0, 4.0:

  • 64 bits version: C:\Windows\System32\WindowsPowerShell\v1.0\
  • 32 bits version: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\
北恋 2024-10-08 09:43:04

我想 $PsHome 有您想要的信息?

PS .> $PsHome
C:\Windows\System32\WindowsPowerShell\v1.0

PS .> Get-Help about_automatic_variables

TOPIC
    about_Automatic_Variables ...

I think $PsHome has the information you're after?

PS .> $PsHome
C:\Windows\System32\WindowsPowerShell\v1.0

PS .> Get-Help about_automatic_variables

TOPIC
    about_Automatic_Variables ...

御弟哥哥 2024-10-08 09:43:04

这是一种方法...

(Get-Process powershell | select -First 1).Path

这可能是一种更好的方法,因为它返回路径上的第一个命中,就像您从命令提示符运行 Powershell 一样...

(Get-Command powershell.exe).Definition

Here is one way...

(Get-Process powershell | select -First 1).Path

Here is possibly a better way, as it returns the first hit on the path, just like if you had ran Powershell from a command prompt...

(Get-Command powershell.exe).Definition
素食主义者 2024-10-08 09:43:04

要获取当前运行的 PowerShell 的完整路径,您可以使用以下命令:

[System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName

生成的路径包含 PowerShell 可执行文件名,这使您可以区分 PowerShell 和 PowerShell ISE(与 $PsHome 不同,它仅显示 PowerShell 文件夹)。此外,与 Get-Process 不同,它不受
系统上运行的其他进程,因此您始终可以获得当前体系结构(32 位或 64 位)的正确路径。

GetCurrentProcess 方法可从 .NET Framework 1.1 和 .NET Core 1.0 获得,因此这应该适用于任何版本的 .NET/PowerShell。

To get the complete path to the currently running PowerShell, you can use this:

[System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName

The resulting path includes the PowerShell executable filename, which allows you to distinguish between PowerShell and PowerShell ISE (unlike $PsHome, which only shows you the PowerShell folder). Also, unlike Get-Process, it is not affected by
other processes running on the system, so you always get the correct path for the current architecture (32-bit or 64-bit).

The GetCurrentProcess method is available from .NET Framework 1.1 and .NET Core 1.0, so this should work on any version of .NET/PowerShell.

ぇ气 2024-10-08 09:43:04

它始终是 C:\Windows\System32\WindowsPowershell\v1.0。这是我在某处听到或读到的,因为向后兼容。

It is always C:\Windows\System32\WindowsPowershell\v1.0. It was left like that for backward compability is what I heard or read somewhere.

心的位置 2024-10-08 09:43:04

我遇到了类似的问题,但事实证明这是与路径相关的问题。
在我的计算机的 Windows 文件夹中也安装了 powershell.exe 的附加副本。请检查路径变量以获取调用了哪个 .exe。

I had a similar issue but it turned out to be an issue related to path.
In my computer in Windows folder too an additional copy of powershell.exe is installed. Please check the path variable to get which .exe is called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文