PowerShell has been a proprietary part of Windows since its introduction in 2006, but this changed in August 2016,...
when PowerShell became open source. It still supports Windows, but Microsoft expanded availability to other major operating systems, including OS X and Linux versions, such as CentOS and Ubuntu.
Let's consider the implications of PowerShell for Linux for IT administrators.
What operating systems does PowerShell currently run on?
The open source version of PowerShell is not a single release, but rather, a variety of releases that accommodate Microsoft Windows, Linux variants, Mac and Docker.
PowerShell support for other operating systems should continue to emerge as the community looks for additional OS coverage. In the meantime, Microsoft maintains its own proprietary version of PowerShell.
Windows versions support Windows 7 (x86), Windows 7 (x64), Windows 8.1 and Windows 10, as well as Windows Server 2012 R2 (x64) and Windows Server 2016 (x64). Each version is available from GitHub as Windows Installer files using MSI file extensions.
Windows 8.1 and Windows Server 2012 R2 will require the latest Visual C++ Redistributable Package for Visual Studio 2015. The file name typically includes the build version and target operating system, such as the following:
PowerShell supports numerous Linux versions, including Ubuntu 14.04, Ubuntu 16.04, CentOS 7, openSUSE 42.1, Oracle Linux 7, Red Hat Enterprise Linux (RHEL) 7 and Arch Linux. Ubuntu users can download and install a Debian package (DEB) file from GitHub, while CentOS, openSUSE, Oracle Linux and RHEL users can download and deploy RPM Package Manager files with an RPM extension. Arch Linux versions are available from the Arch User Repository, rather than GitHub.
Apple users can download a package (PKG) file for OS X 10.11 systems. To install it, they can download the latest release version from GitHub to the OS X system, then double-click the downloaded file and follow the prompts to complete the installation.
Container users can employ a Docker version of PowerShell. Docker provides release and beta builds as Docker files that can build and run PowerShell in a container for each supported Linux distribution. This requires Docker 1.12 or later, and does not allow for the sudo command.
How different is the open source PowerShell version?
The open source version of PowerShell has morphed into about a dozen different versions to support various Windows, Linux, Mac and Docker environments. Many of these versions are not fully interchangeable; users must select and install the proper PowerShell version for their operating system.
The command set is not universal across all operating systems. In general, open source PowerShell only provides a subset of modules and cmdlets found in the full, proprietary version. In other cases, some commands present in one operating system aren't suitable for other operating systems, and are removed to shrink the distribution package size. As an example, Windows commands, such as Get-Service or Get-Eventlog, aren't available on PowerShell for Linux.
Command aliases pose a challenge
Another difference between PowerShell versions is the treatment of command aliases. The Windows versions of PowerShell provide aliases that map to Linux command names. This translates Linux commands to Windows PowerShell commands to ensure PowerShell can work with the responses.
However, Microsoft removed aliases for Linux and Mac distributions. Linux administrators can use native Linux commands, such as ls, cp and mv in PowerShell, alongside similar PowerShell commands, such as dir. However, Linux commands return strings, rather than objects.
When an administrator uses a Linux-native command, PowerShell may not know what to do with the response. This can limit scripting or other functionality in PowerShell for Linux.
Consider the available commands for your preferred PowerShell version during the test and evaluation stage. Decide whether the open source tool is adequate for your systems management purposes.
Fortunately, open source PowerShell supports the get-module -list command to show exactly what features and functions are available under management, security, utility and other areas. Each version also provides the same help feature that explains each available command, and the proper syntax for its usage. This allows IT professionals to explore each respective version directly.
How does script creation in PowerShell for Linux differ from the native Windows version?
The process of script creation in open source PowerShell is basically identical to the version installed on current Microsoft operating systems. For example, open source PowerShell allows administrators to create pipelined behaviors, establish a desired state configuration for systems and integrate with the Operations Management Suite for control of workloads across Azure and other clouds.
PowerShell scripts are text files that are parsed and interpreted during execution to produce a desired sequence of actions. Windows operating systems support the native PowerShell Integrated Scripting Environment (ISE) for script creation and edits. However, versions of PowerShell for Linux and Mac OS X do not support the ISE. Administrators can use other text editors, such as Visual Studio (VS) Code, to create and manage PowerShell scripts.
Once you prepare a script, debug it to find and fix mistakes. Don't try to debug code after it's already in a production environment. You can use a debugging tool to check scripts. Tools like VS Code, for example, include a debugger that can perform tasks like command-syntax checks.
Once a PowerShell script passes the debugger test, still test it as a separate process to ensure it produces the required result, without a potential problem in production. The open source PowerShell community often uses the Pester tool to create test cases to find the script and gauge results.
Are there any other considerations for open source PowerShell?
PowerShell scripts must have a PS1 file extension; other extensions may cause the script to fail, or cause problems with the exchange of some objects.
PowerShell also supports Just Enough Administration (JEA) to allow for limited or temporary administrative authority. However, JEA functionality is absent in the Linux and Mac OS X PowerShell versions, and is not currently planned for PowerShell 6.0.
PowerShell has typically been insensitive to case, but other operating systems, like Linux, can be case-sensitive with file names and the exclusive use of forward slashes. This means errors with filename case usage and paths can cause modules not to load. For example, if the name of the module in the script doesn't match the case of the module's file name, it won't load properly. Case problems can also interfere with automatic tab completion tasks.
In addition, wildcards only work for built-in, not external, commands. For example, a command like ls *.exe will fail because the * wildcard won't work properly without a workaround.
The Linux and Mac OS X versions of PowerShell do not offer job control or schedule support. Foreground job and background job commands don't work. Client-side remoting is also absent in PowerShell for Linux and Mac OS X. And there is no support for Windows Management Instrumentation or Common Information Model commands on Linux. The developer community will likely resolve some of these issues in future PowerShell releases.
Avoid the limitations of PowerShell scripts
Explore PowerShell's Desired State Configuration feature
Microsoft's open source strategy represents something bigger