7

My Computer Science professor gave a quiz, and one of the questions was "true or false: PowerShell works in Windows, Mac and Linux"; the correct answer was "false." He maintains that PowerShell is only a Windows thing. But here are a couple of websites that say otherwise:

https://azure.microsoft.com/en-us/blog/powershell-is-open-sourced-and-is-available-on-linux/

https://github.com/PowerShell/PowerShell

So which one is true? Does PowerShell work for Linux and Mac as well as Windows?

5
  • 2
    I think you've already got your answer with reliable sources. Now, you may not be able to use many of the Powershell Cmdlets you know and love today on Windows on Mac/Linux, but the Powershell environment does run on Max/Linux. – heavyd May 3 '17 at 20:55
  • 1
    Looks like you did your research and it seems like good opportunity for you, by discussing this topic, to either improve relationship with a professor or make it worse (depending on his personality) :) – sickelap May 3 '17 at 21:43
  • 3
    It does indeed work on Linux. – Ramhound May 3 '17 at 22:07
  • Powershell is primarily windows based, but technically you could force it to work with other operating systems. So you're correct by technicality. – Bennett Yeo May 3 '17 at 22:12
  • 4
    @BennettYeo Powershell literally was ported to Linux, nothing, technically about it more actually – Ramhound May 4 '17 at 1:43
10

Yes.

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

As you found in the PowerShell repository on GitHub, quite a few OSes and distributions are supported. For example, here are the instructions for Ubuntu. Demonstration (source page):

PowerShell working on Ubuntu

One could argue that not all of PowerShell is available in non-Windows environments. Some features depend on libraries only found on 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's nothing there. And, of course, there are cmdlets to manage systems only found on Windows, like Modern apps (Get-AppxPackage and friends).

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

2

The latest powershell for macos (6 alpha) has better .net support. But it only works in Sierra osx. For example, this works now where before it didn't:

$ping = New-Object System.Net.Networkinformation.ping
$ping.Send('yahoo.com', 500) # timeout 500 ms

[Net.DNS]::GetHostEntry('yahoo.com')   

The default console colors are terrible though (yellow for commands, etc).

set-psreadlineoption command darkyellow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.