Windows PowerShell is an excellent configuration management and automation framework. It's comprised of a command line shell and .NET-based scripting language. Administrators use PowerShell as a means of managing Windows, Linux, and networked clients.

In 2016, Microsoft open-sourced PowerShell and debuted a cross-platform iteration. This .NET Core version offers Linux and macOS installers. Because system administrators often use Linux, PowerShell on Linux brought lots of new functionality. Although it's essentially the same program, there are key differences such as the ability to run standard Bash commands in Linux PowerShell.

In this article I'm going to show you how to install, run, and use PowerShell on Linux!

What Is Windows PowerShell?

Windows PowerShell is a command-line framework for configuration management and task automation. Offering complete WMI and COM access, PowerShell enables administrators to manage remote and local Windows systems. CIM and WS-Management make PowerShell capable of managing network devices as well as Linux systems. Although PowerShell and Command Prompt may appear similar, they definitely differ.

In 2016, Windows debuted its "Windows loves Linux" campaign. Among the Linux-Windows partner projects was Bash on Windows. Users running the Windows 10 Anniversary Update can install a full Linux subsystem on Windows machines. This yields access to the command line. You can install and run various GUI programs. However, using the command line is the true intent behind Bash for Windows.

Installing PowerShell on Linux (With Command Line)

Start by downloading the appropriate PowerShell on Linux installer from the GitHub page. You can find installers for Ubuntu 16.04 and 14.04, Red Hat Enterprise Linux 7 and CentOS 7, and macOS. Start by downloading the correct installer for your operating system. I'm running Ubuntu 16.04 so I downloaded the Ubuntu 16.04 DEB. However the installer should work for any Ubuntu derivative like Lubuntu and Xubuntu.

Ubuntu users will have a DEB package whereas CentOS and RHEL users will use an RPM. The macOS installer is a PKG.

PowerShell Downloads

Because PowerShell is a command line utility, let's first look at installing PowerShell via the Linux command line. Note where your PowerShell DEB is downloaded. Typically this will be the default "Downloads" directory. Once you've located the package, run the following command:

        sudo apt-get install libunwind8 libicu55
sudo dpkg -i /path/to/your/powershell.deb

Replace the "path to" line with the correct folder path and exact DEB. I used the Ubuntu 16.04 package and the DEB was located in my "Downloads" directory. Therefore the command I ran looked like:

        sudo apt-get install libunwind8 libicu55
sudo dpkg -i /home/moe/Downloads/powershell_6.0.0-alpha.14-1ubuntu1.16.04.1_amd64.deb

This installs Windows PowerShell and its dependencies. Because we're installing with super user permissions, you'll be prompted for your password during the install.

PS-Nix-PW

Wait as the install wraps up. You'll see some lines about preparing to unpack PowerShell and setting up PowerShell. Once this concludes, you're ready to begin using PowerShell.

Install-PS-Nix-CL

Installing PowerShell on Linux (No Command Line)

Alternatively, you can install Windows PowerShell on Linux without using the command line. If you're installing PowerShell, chances are you have no fear of using the command line. Turn back now if you do. But for simplicity's sake you can merely run the package installer via the Ubuntu Software Center. Double click the DEB to open it with the Ubuntu Software Center. From here, click Install.

PowerShell Software Center

As with the command line installation, you'll be prompted for your password.

PS-Nix-Auth

Once the PowerShell install finishes you'll see a notification that the process has completed.

Using PowerShell on Linux

Running Windows PowerShell on Linux requires the command line. Unlike many programs, you can't simply find and launch the program by searching. Open a new terminal and type:

        powershell
    

This brings up the lines:

        PowerShell

Copyright (C) 2016 Microsoft Corporation. All rights reserved.

Beneath that there's a line of:

        PS /home/moe>
    

From here, you can use Windows PowerShell exactly as you would on Windows. Simply run PowerShell cmdlets like normal. For instance, we can run:

        Get-ChildItem -Path /
PS-Nix-Example

This outputs a list of the folders and files in a system drive. Any command that functions in PowerShell on Windows should work properly on Linux. To test, I also ran:

        Enable-PSBreakpoint
    

This command enables breakpoints in the console. For a list of common PowerShell commands, try these basic PowerShell commands. For a deep dive, check out this helpful blog post with loads of commands. There are some key differences though. In PowerShell on Linux, you can use native Linux commands or the PowerShell variants. So PowerShell on Linux acts as a hybrid of the Linux command line and PowerShell. Various commands such as...

        ls
    

...work exactly as they would in a standard terminal. Now that you've got PowerShell up and running, learn how to boost your productivity using PowerShell scripts.

Uninstalling PowerShell on Linux

Uninstalling PowerShell is incredibly simple. Open a terminal and run:

        sudo apt-get remove powershell
    

You'll receive a prompt asking if you'd like to proceed. Press Y to continue with the uninstall.

I've Got the Power(Shell)

Windows coming to PowerShell was huge. First, there's the functionality to manage a bevy of systems cross-platform. System administrators notably favor Linux. Because of its enhanced security and permissions as well as the flexibility of the command line, sysadmins benefit from Linux ecosystems. Further, introducing PowerShell on Linux continued the claim that Microsoft does indeed love Linux. Bash on Windows offered a great solution for maintaining the command line in a Windows environment.

But PowerShell is a scripting utility for Linux, not a Linux feature on Windows. Plus, Microsoft open-sourced PowerShell, a move that definitely satisfies Linux users. Moreover, rather than merely PowerShell on Linux this version lets you input both standard Linux commands and PowerShell commands. Thus, it's a superb hybrid solution.

Microsoft's investment in .NET Core in large part made open-sourcing PowerShell feasible. .NET Core is another open-source project. The current open-source iteration of PowerShell is based on .NET Core. As such, the Linux PowerShell carries any dependency limitations that .NET Core features. Ultimately, PowerShell on Linux is a major migration toward cross-platform system management.

Are you using PowerShell on Linux? Tell us your thoughts on the Linux PowerShell in the comments section below!