Pinterest Stumbleupon Whatsapp
Advertisement

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 Command Prompt vs. Windows PowerShell: What's the Difference? Command Prompt vs. Windows PowerShell: What's the Difference? Windows users can get by without using either the Command Prompt or PowerShell. But with Windows 10 and new features around the corner, maybe it's about time we learned. Read More .

In 2016, Windows debuted its “Windows loves Linux” campaign. Among the Linux-Windows partner projects was Bash on Windows A Quick Guide to Linux Bash Shell in Windows 10 A Quick Guide to Linux Bash Shell in Windows 10 You can now run Linux on Windows. Learn more about Bash on Windows, from how and why you should install it, to hidden features you probably didn't know about. Read More . Users running the Windows 10 Anniversary Update can install a full Linux subsystem on Windows Windows 10 Receives a Full Linux Command Prompt Windows 10 Receives a Full Linux Command Prompt BASH shell, complete with a Linux sub-system, is coming to Windows 10 with the Anniversary Update this summer. That was one of the biggest announcements at the Build Developer Conference. Here's why this matters. Read More 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 6 Basic PowerShell Commands to Get More out of Windows 6 Basic PowerShell Commands to Get More out of Windows PowerShell is what you get when you give steroids to the Windows Command Prompt. It grants you control of nearly every aspect of the Windows system. We help you leap up its learning curve. Read More . 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 Boost Your Productivity With Windows PowerShell Scripts Boost Your Productivity With Windows PowerShell Scripts What if you could bring the productivity of Linux over to Windows? Most Linux distros come packaged with the powerful Bash shell. PowerShell is an equally powerful terminal for Windows. Read More .

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 A GNU Beginning For Microsoft: What An Open Source .NET Framework Means For The Rest Of Us A GNU Beginning For Microsoft: What An Open Source .NET Framework Means For The Rest Of Us Microsoft just released a significant part of its code under a permissive open source license. This move breaks with years of tradition. But why and what does it mean for you? Read More 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!

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. John Smith
    February 6, 2017 at 9:00 am

    Unless if you are working to migrate Windows garbage to Linux, you are wasting your time. Even that can be done with Linux native scripting and software. I see no use whatsoever for powershell on Linux.

  2. J
    January 21, 2017 at 8:10 am

    Why TF would you use an inferior product by an inferior company if you can use Bash or any other shell without infecting your system with Microsoft crap?

  3. KHY
    January 20, 2017 at 5:53 pm

    The tool will be more useful if the tool can have remote capabilities to manage Microsoft Infrastructure and do cross platform administration. I doubt Microsoft will port winrm to Linux anytime soon.

    # Enable-PSRemoting -Force
    Enable-PSRemoting : The term 'Enable-PSRemoting' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
    that the path is correct and try again.
    At line:1 char:1
    + Enable-PSRemoting -Force
    + ~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Enable-PSRemoting:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException