5 Things to Know About PowerShell Core on Linux

powershell hero 16 9 ratio
For many long time PowerShell users, the introduction of PowerShell to Linux was a welcome addition. Now IT Pros with cross-platform management responsibilities could leverage the same skill set. But PowerShell Core, which is the version available on non-Windows platforms, is not quite the same beast as its Windows PowerShell counterpart. I expect many readers are familiar with the latter. For those of you jumping into PowerShell on Linux, here are 5 things you’ll want to keep in mind.
 

 

No WMI or CIM

First, many Windows PowerShell scripters are used to using commands like Get-WmiObject or Get-CimInstance to retrieve management information. There are also a number of commands that rely on WMI under the hood like Restart-Computer. In the PowerShell Core world on Linux, these commands don’t exist. The reason is simple: there is no CIM infrastructure on Linux platforms. This isn’t a defect in PowerShell, just a recognition of the platform. In much the same way, there is no Get-Service command on Linux because it doesn’t have “services” in the Windows sense. Now, this doesn’t mean all hope is lost. There is a long-term solution in play that involves OMI (Open Management Infrastructure). If you do a web search for “linux omi”, you’ll find a number of results, including references to Microsoft’s plans regarding OMI and Linux. Once these bits are in place, the CIM story will change but for now, you’ll have to live without it.

No Scheduled PowerShell Jobs

This one makes sense when you think about it, but I sure miss it. PowerShell Core on Linux has support for background jobs. You can run commands with Start-Job. You can even kick off a task as a background job in Linux fashion.

PowerShell background jobs in Linux (Image Credit: Jeff Hicks)
PowerShell Background Jobs in Linux (Image Credit: Jeff Hicks)

But the scheduled job cmdlets do not exist. I guess I can’t expect them to since they are designed to work with the Windows Task Scheduler. I’m hoping that at some point there is a version that will use Linux task schedulers like cron.

Beware of Aliases

In Windows PowerShell, Microsoft provided a number of aliases like ls and ps. These were intended as transition aids for Linux admins coming to Windows PowerShell. In PowerShell Core on Linux, any alias that is also a native Linux command is out. When you use the ps alias in Linux, it is the ps command.

No Linux aliases (Image Credit: Jeff Hicks)
No Linux Aliases (Image Credit: Jeff Hicks)

This also applies to aliases you may have gotten into the habit of using like Sort. This is a native command, so you’ll need to get in the habit of using Sort-Object. There are still plenty of aliases used in PowerShell Core but you might have a bit of a learning curve figuring out what you can no longer use.

Remoting via SSH

Just as Linux doesn’t natively support CIM, so too is a lack of support for WSMan. There’s no Enable-PSRemoting cmdlet. No WSMan: PSDrive with a TrustedHosts setting. This also means no JEA or DSC. Remoting in PowerShell Core will be done with SSH. I won’t get into the details here but jump to https://github.com/PowerShell/PowerShell/tree/master/demos/SSHRemoting if you want a quick overview. Once you have an SSH connection, the remoting experience is pretty much the same. Microsoft realizes this is an area that needs attention, so expect to see changes in future releases.

Help Needs Help

The last item you’ll need to be aware of is help documentation. In the past, I’ve always encouraged people to read the help but in the Linux world with PowerShell, now I’m not so sure. Because PowerShell Core will also run on Windows platforms, features that don’t work in Linux might still work there, such as remoting with WSMan. This means that when you look at help for a command like Invoke-Command, you’ll see content that perhaps doesn’t apply to Linux. Sadly, I don’t have a good answer for you now. If you get stuck on something, you can always post your question in the forums at PowerShell.org. Perhaps at some point help will be more platform aware.
Now, don’t get me wrong. I love being able to use PowerShell on Linux. I can get more done with PowerShell Core than I can with Linux, as my Linux-fu skills are lacking. Although from personal experience, one other gotcha for Windows people is that Linux is so gosh-darn case-sensitive. PowerShell commands are not but just about everything else is. And if you’re wondering where you can get your hands on a PowerShell installation for your favorite Linux distro, head over to https://github.com/PowerShell/PowerShell and look through the README.