Install and Get Started with PowerShell on Ubuntu

29/12/2020
PowerShell is a task based configuration tool used for automation and configuration of Windows operating system. It is a very powerful tool built on top of .NET framework. Microsoft has released PowerShell Core for Linux operating systems. PowerShell core is built on top of .NET core.

Administrators can perform different administrative tasks on the local computer, or on a remote computer using PowerShell. It’s a very powerful command line tool.

PowerShell is also a very powerful scripting language for system administration. You can write very complex scripts with PowerShell to help you automate your everyday system administration tasks.

In this article, I am going to show you how to install PowerShell on Ubuntu 18.04 LTS and also how to get started with PowerShell. So, let’s dig in.

Installing PowerShell on Ubuntu 18.04 LTS:

PowerShell is not available in the official package repository of Ubuntu 18.04 LTS. But, you can easily add the official Microsoft package repository on Ubuntu 18.04 LTS and install PowerShell from there using the APT package manager.

First, navigate to the /tmp directory with the following command:

$ cd /tmp

Now, download the Microsoft package repository installer DEB package file with the following command:

$ wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

Now, install the Microsoft package repository installer DEB package with the following command:

$ sudo apt-get install ./packages-microsoft-prod.deb

Microsoft package repositories should be enabled.

Now, update the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated. As you can see, Microsoft package repository is listed here as well. So, Microsoft package repository is being used.

Now, you can install PowerShell on your Ubuntu 18.04 LTS machine.

To install PowerShell on your Ubuntu 18.4 LTS machine, run the following command:

$ sudo apt install powershell

To confirm the installation, press y and then press <Enter>.

PowerShell should be installed.

Now, to check whether PowerShell is working or not, run the following command:

$ pwsh –version

The PowerShell version information should be printed on the console. As you can see, I am running PowerShell 6.2.0. It may be different by the time you read this article.

Starting PowerShell:

Now that PowerShell is installed, you can start it with the following command:

$ pwsh

PowerShell should start. Now, you can start running PowerShell commands, write PowerShell scripts, run PowerShell scripts and many more.

Getting Started with PowerShell on Ubuntu 18.04 LTS:

In this section of the article, I am going to show you the basics of PowerShell. So, let’s get started.

PowerShell has support for all the common cmd.exe and Unix commands. For example, cat, dir, rm, echo, cls, cd etc.

On Linux, you can use any of the existing Linux commands from PowerShell. As you can see, I ran the apt and whoami Linux commands and it ran successfully.

PowerShell uses a more descriptive aliases for the Windows cmd.exe commands such as dir, cd, cls etc.

You can use the Get-Alias command of PowerShell to find the alias of your desired commands.

For example, to find the alias of the cd command, use Get-Alias as follows:

PS> Get-Alias cd

As you can see, the alias is Set-Location. PoweShell commands are really easy to remember.

As you can see, I can use the Set-Location command to navigate to another directory.

PowerShell also has powerful auto completion features. You use <Tab> the same way as you do on Linux to get auto completion.

If you prefer short commands, PowerShell also got your back. PowerShell provides some standard aliases for that.

Earlier, I used the Get-Alias command. But, I could’ve used a shorter alias gal. It would give me the same result as you can see in the screenshot below.

PS> gal cd

Here, g is for Get and al is for Alias.

The same way, you can use sal instead of the Set-Alias command. Here, s is for Set and al is for Alias.

For more information on command alias, take a look at the official documentation of PowerShell at https://docs.microsoft.com/en-us/powershell/scripting/learn/using-familiar-command-names?view=powershell-6

On Linux we have man pages. Man pages help us learn what the command is used for, what command options are available, what each of the options do and many more. The same way, you can get help on PowerShell commands.

On PowerShell, the Get-Help command is used to get help on your desired command.

For example, to get help on the Set-Location command we have seen earlier, run the following command:

PS> Get-Help Set-Location

As you can see, the Get-Help command shows the NAME of the command, the SYNTAX of the command, the ALIASES of the command. But it should show more!

In the earlier example, you’ve seen that the Get-Help command could not find the Help files of the command in my computer. So, it displayed partial help. I actually did not have the Help files downloaded for that command.

To download the Help files on your computer, run the following PowerShell command:

PS> Update-Help

As you can see, PowerShell is downloading and installing the help files.

Once the help files are downloaded, let’s try to get help on the Set-Location command again.

PS> Get-Help Set-Location

Nothing changed! Well, by default, partial help is displayed. But, you can view full help if you want now.

To display full help on the Set-Location command, run Get-Help as follows:

PS> Get-Help Set-Location -Full

As you can see, the full help is displayed. The full help contains examples as well as explanation of every options.

If you don’t want to download Help files, you can also find help online with the Get-Help command as follows:

PS> Get-Help Set-Location -Online

A web browser will open up with the help page for Set-Location as you can see.

The online help page also has examples.

Now that you know how to run commands and how to get help on PowerShell, you should be able to start learning more about it. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Google Hangouts on Ubuntu 18.04

If you’re a chatter, you already know about all the popular chat clients that allow instant access to all your friends....
29/12/2020

Rufus Bootable USB to Install Ubuntu 18.04 LTS

In this article, I will show you how to use Rufus to make a bootable USB drive from Windows and use it to install Ubuntu...
28/12/2020

How to Install and Configure Consul Server on Ubuntu 18.04

Consul is an open source service discovery tool which is based and built on Golang. It helps you discovering services application...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024