CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Wednesday, May 25, 2022

Install Windows PowerShell on Rocky Linux 8

Install Windows PowerShell on Rocky Linux

In this article, you will learn how to install Windows PowerShell on Rocky Linux or other RPM based Linux distros.

 

Table of Contents:

 

What is Windows PowerShell?:

PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-source and cross-platform on 18 August 2016 with the introduction of PowerShell Core. The former is built on the .NET Framework, the latter on .NET Core.

In PowerShell, administrative tasks are generally performed via cmdlets (pronounced command-lets), which are specialized .NET classes implementing a particular operation. These work by accessing data in different data stores, like the file system or Windows Registry, which are made available to PowerShell via providers. Third-party developers can add cmdlets and providers to PowerShell. Cmdlets may be used by scripts, which may in turn be packaged into modules. Cmdlets work in tandem with the .NET API.

PowerShell includes its own extensive, console-based help (similar to man pages in Unix shells) accessible via the Get-Help cmdlet. Updated local help contents can be retrieved from the Internet via the Update-Help cmdlet. Alternatively, help from the web can be acquired on a case-by-case basis via the -online switch to Get-Help. (Source: Wikipedia)

Recommended Training: Windows PowerShell Begginer to Intermediate

Recommended Book: Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS 4th Edition by Travis Plunk, James Petty and Leon Leonhardt

Install Windows PowerShell on Rocky Linux

Update Linux Operating System:

By using a SSH client, connect with rockylinux-01.centlinux.com as root user.

Build cache for installed yum repositories.

# dnf makecache
Rocky Linux 8 - AppStream                       1.3 kB/s | 4.8 kB     00:03
Rocky Linux 8 - BaseOS                          1.2 kB/s | 4.3 kB     00:03
Rocky Linux 8 - Extras                          1.0 kB/s | 3.1 kB     00:03
Metadata cache created.

Execute following command to update software packages that are already installed on your Rocky Linux operating system.

# dnf update -y
Last metadata expiration check: 0:01:01 ago on Mon 23 May 2022 07:13:55 PM PKT.
Dependencies resolved.
Nothing to do.
Complete!

Our Linux server is already up-to-date. So, there is has nothing to update. But the output may vary on your Linux server.

After updating your Linux server, Check the versions of your operating system and Linux Kernel as follows.

# cat /etc/rocky-release && uname -r
Rocky Linux release 8.6 (Green Obsidian)
4.18.0-372.9.1.el8.x86_64

 

Install Windows PowerShell on Rocky Linux:

First of all import the GPG key of Microsoft Official yum Repository by using rpm command.

# rpm --import https://packages.microsoft.com/keys/microsoft.asc

Download and install Microsoft Official yum repository on your Rocky Linux server.

# dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
Last metadata expiration check: 0:08:20 ago on Mon 23 May 2022 07:13:55 PM PKT.
packages-microsoft-prod.rpm                     7.7 kB/s | 6.8 kB     00:00
Dependencies resolved.
================================================================================
 Package                      Arch        Version       Repository         Size
================================================================================
Installing:
 packages-microsoft-prod      noarch      1.0-1         @commandline      6.8 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 6.8 k
Installed size: 204
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : packages-microsoft-prod-1.0-1.noarch                   1/1
  Verifying        : packages-microsoft-prod-1.0-1.noarch                   1/1

Installed:
  packages-microsoft-prod-1.0-1.noarch

Complete!

Rebuild cache for newly installed yum repositories.

# dnf makecache
Rocky Linux 8 - AppStream                       1.2 kB/s | 4.8 kB     00:04
Rocky Linux 8 - BaseOS                          1.6 kB/s | 4.3 kB     00:02
Rocky Linux 8 - Extras                          1.2 kB/s | 3.1 kB     00:02
packages-microsoft-com-prod                     745 kB/s | 3.4 MB     00:04
Metadata cache created.

List down the available powershell packages as follows.

# dnf search powershell
Last metadata expiration check: 0:00:47 ago on Mon 23 May 2022 07:24:11 PM PKT.
====================== Name & Summary Matched: powershell ======================
powershell.x86_64 : PowerShell is an automation and configuration management
                  : platform.
powershell-lts.x86_64 : PowerShell is an automation and configuration management
                      : platform.
powershell-preview.x86_64 : PowerShell is an automation and configuration
                          : management platform.

                          : management platform.

By using dnf command, install the Windows PowerShell on your Rocky Linux server.

# dnf install -y powershell
Last metadata expiration check: 0:01:13 ago on Mon 23 May 2022 07:24:11 PM PKT.
Dependencies resolved.
================================================================================
 Package       Arch      Version           Repository                      Size
================================================================================
Installing:
 powershell    x86_64    7.2.4-1.rh        packages-microsoft-com-prod     66 M
Installing dependencies:
 libicu        x86_64    60.3-2.el8_1      baseos                         8.8 M

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 74 M
Installed size: 213 M
Downloading Packages:
(1/2): libicu-60.3-2.el8_1.x86_64.rpm           312 kB/s | 8.8 MB     00:28
(2/2): powershell-7.2.4-1.rh.x86_64.rpm         878 kB/s |  66 MB     01:16
--------------------------------------------------------------------------------
Total                                           975 kB/s |  74 MB     01:18
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : libicu-60.3-2.el8_1.x86_64                             1/2
  Running scriptlet: libicu-60.3-2.el8_1.x86_64                             1/2
  Installing       : powershell-7.2.4-1.rh.x86_64                           2/2
  Running scriptlet: powershell-7.2.4-1.rh.x86_64                           2/2
  Verifying        : libicu-60.3-2.el8_1.x86_64                             1/2
  Verifying        : powershell-7.2.4-1.rh.x86_64                           2/2

Installed:
  libicu-60.3-2.el8_1.x86_64            powershell-7.2.4-1.rh.x86_64

Complete!

To verify installation of Windows PowerShell, execute following command at Linux bash prompt to check the version of installed pwsh command.

# pwsh -v
PowerShell 7.2.4

Windows PowerShell is successfully installed on your Linux server.

 

Execute PowerShell Commands in Linux:

Execute pwsh command to start PowerShell and execute some test commands thereon.

# pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /root> Get-Date

Monday, May 23, 2022 7:31:14 PM

PS /root> Get-PSDrive

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
/                   2.49         35.73 FileSystem    /
Alias                                  Alias
Env                                    Environment
Function                               Function
Temp                2.49         35.73 FileSystem    /tmp/
Variable                               Variable

PS /root> exit

 

Conclusion:

In this article, you have learned how to install Windows PowerShell on Rocky Linux and other RPM based Linux distros.

If you find this article useful? Consider supporting us by Buy Me A Coffee


No comments:

Post a Comment

© 2023 CentLinux. All Rights Reserved.