PowerShell是否可以在Windows以外的其他操作系统上运行?

PowerShell是否可以在Windows以外的其他操作系统上运行?

It can be very frustrating when your professor says one thing about PowerShell and various websites seem to offer solid proof to the contrary. Does PowerShell actually work on non-Windows systems or not? Today’s SuperUser Q&A post has the answer to a puzzled reader’s question.

当您的教授对PowerShell发表一件事而各种网站似乎提供了相反的可靠证据时,这可能会非常令人沮丧。 PowerShell是否可以在非Windows系统上正常工作? 今天的《超级用户问答》帖子解答了一个困惑的读者的问题。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

问题 (The Question)

SuperUser reader FredSavage187 wants to know if PowerShell works on other operating systems besides Windows:

超级用户读者FredSavage187想知道PowerShell是否可以在Windows以外的其他操作系统上运行:

My computer science professor recently gave us a quiz and one of the questions was, “True or False: PowerShell works on Windows, Mac, and Linux”. The correct answer was “false” and he maintains that PowerShell is a Windows only thing. But I found a couple of websites that say otherwise:

我的计算机科学教授最近给我们进行了一个测验,其中一个问题是:“对还是错:PowerShell可以在Windows,Mac和Linux上运行”。 正确答案是“假”,他坚持认为PowerShell仅是Windows。 但是我发现有两个网站另有说明:

PowerShell is open sourced and is available on Linux [Microsoft Azure Blog]

PowerShell是开源的,可在Linux上使用 [Microsoft Azure博客]

PowerShell Repository [GitHub]

PowerShell存储库 [GitHub]

Which one is actually correct? Does PowerShell work on Linux and Mac OS as well as Windows?

哪一个是正确的? PowerShell是否可以在Linux和Mac OS以及Windows上运行?

Does PowerShell work on other operating systems besides Windows?

PowerShell是否可以在Windows以外的其他操作系统上运行?

答案 (The Answer)

SuperUser contributor Ben N has the answer for us:

超级用户贡献者Ben N为我们提供了答案:

Yes. Much of PowerShell is .NET, so it can run on any operating system that has the Common Language Runtime (CLR). On Windows, that is the .NET Framework. For other operating systems, including Linux, you can use the CoreCLR, an open-source, cross-platform subset of the .NET Framework.

是。 PowerShell大部分是.NET,因此它可以在具有公共语言运行时(CLR)的任何操作系统上运行。 在Windows上,这就是.NET Framework。 对于包括Linux在内的其他操作系统,可以使用CoreCLR (.NET Framework的开源,跨平台子集)。

As you learned at the PowerShell repository on GitHub, quite a few operating systems and distributions are supported. For example, here are the instructions for Ubuntu and a demonstration:

正如您在GitHub上的PowerShell存储库中了解到的那样,支持许多操作系统和发行版。 例如,这是Ubuntu说明和一个演示

PowerShell是否可以在Windows以外的其他操作系统上运行?

One could argue that not all of PowerShell is available in non-Windows environments since some features depend on libraries found only in Windows. The ParsedHtml property on the HtmlWebResponseObject type returned by Invoke-WebRequest, for example, is only useful on Windows because it holds a COM object that comes from an unmanaged library, mshtml.dll to be specific. On other platforms, there is nothing there. And, of course, there are cmdlets to manage systems found only in Windows, like Modern apps (Get-AppxPackage, for example).

有人可能会说,并非所有PowerShell都可以在非Windows环境中使用,因为某些功能取决于仅在Windows中找到的库。 例如,由Invoke-WebRequest返回的HtmlWebResponseObject类型的ParsedHtml属性仅在Windows上有用,因为它包含来自非托管库(具体为mshtml.dll)的COM对象。 在其他平台上,没有任何东西。 而且,当然,有cmdlet可以管理仅在Windows中找到的系统,例如Modern应用程序(例如Get-AppxPackage )。

Still though, the PowerShell infrastructure works perfectly well on other operating systems, plenty of the cmdlets are usable anywhere, and support is only getting better.

尽管如此,PowerShell基础结构在其他操作系统上也能很好地运行,许多cmdlet都可以在任何地方使用,并且支持只会越来越好。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

Image Credits: Jeff Hicks (Petri IT Knowledgebase)

图片来源: Jeff Hicks(Petri IT知识库)

翻译自: https://www.howtogeek.com/306261/does-powershell-work-on-other-operating-systems-besides-windows/