LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Open Source PowerShell on Linux

lowendtutorial

PowerShell is now open source, and available for Linux and Mac. You can download official packages from Microsoft for the 64-bit versions of Ubuntu 16.04, Ubuntu 14.04, CentOS 7, Red Hat Enterprise Linux 7, and Mac OS X 10.11. In this article we will discuss how install and use Powershell on Ubuntu 16.04.

First of all connect to your Linux VPS via SSH. You can do that using Putty if you are on a Windows workstation or using SSH if you have a Linux or OSX workstation.

Visit the PowerShell project’s Releases page on GitHub to find the packages. Download the appropriate one for your operating system, in this case we will download the package ending in “16.04.1_amd64.deb” using the following command:

> wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb

Before installing the powershell package we will need a few dempendencies. Run the following command first:

> sudo apt-get install libunwind8 libicu55

Once the installation process will end, you will be able to install the powershell package using the following command assuming you are in the directory where you downloaded the program:

> sudo dpkg -i powershell_6.0.0-alpha.9-1ubuntu1.16.04.1_amd64.deb

We are now ready to execute our powershell environment using the following command:

> powershell

If everything was installed correctly you should get the following output:

PowerShell

Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS /path/to/directory>

Let’s now take a look on some basic useful commands that you can execute in a powershell environment:

> Get-Command

The Get-Command is one of the most useful cmdlets in the whole of PowerShell, as it will help you getting to grips with PowerShell by letting you search for certain cmdlets. Using Get-Command on its own is admittedly not very useful as its just going to spit out every command that PowerShell has. But from this we can see that that objects that PowerShell outputs have both a Name and a ModuleName property. Using this information we can find all cmdlets that contain the word “IP”:

> Get-Command –Name *IP*

Once you have found the cmdlet you are looking for using Get-Command, you are going to want to know the syntax and how you can use that specific cmdlet. This is where Get-Help comes in.

> Get-Help Get-Process

Let’s see some other very usefull commands.

> get-process

To get a list of the running processes.

> get-process calc.exe | StopProcess

To stop a process.

> gc file.txt | select -first 10

Show the first 10 lines of a file.

> gc file.txt | select -last 10

Show the last 10 lines of a file.

> gc file.txt | Measure-Object -Line

Count the lines of a file.

> Select-Text example file.txt

Print lines that contain the word “example”.

There’s actually a lot of built in aliases in PowerShell already so if you find yourself writing some long command string you might be pleased to know that their is probably already a shortcut for it already. You can find out what these are with the following command:

> Get-Alias

As you can see there are a few items in the list that would be familiar to you if you are from a Linux background. Aliases such as ls, cat and rm are just a few examples of aliases that you won’t need to re-learn (or set up) for PowerShell.

No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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