Skip to main content

RHEL: Install Powershell Core

Illustration: Microsoft loves Linux

Check if Powershell Core is installed by trying running pwsh command.

[tuyendq@rhel1 ~]$ pwsh
-bash: pwsh: command not found
[tuyendq@rhel1 ~]$ sudo yum install -y powershell
Loaded plugins: product-id, search-disabled-repos, subscription-manager
epel/x86_64/metalink                                     |  22 kB     00:00
epel                                                     | 4.7 kB     00:00
(1/3): epel/x86_64/updateinfo                              | 986 kB   00:00
(2/3): epel/x86_64/primary_db                              | 6.6 MB   00:00
(3/3): jdoss-wireguard/x86_64/primary_db                   | 3.8 kB   00:01
No package powershell available.
Error: Nothing to do
[tuyendq@rhel1 ~]$ curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   193  100   193    0     0    400      0 --:--:-- --:--:-- --:--:--   400
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
[tuyendq@rhel1 ~]$ sudo yum install -y powershell                               Loaded plugins: product-id, search-disabled-repos, subscription-manager
packages-microsoft-com-prod                              | 2.9 kB     00:00
packages-microsoft-com-prod/primary_db                     | 162 kB   00:00
Resolving Dependencies
--> Running transaction check
---> Package powershell.x86_64 0:6.2.0-1.rhel.7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package       Arch      Version           Repository                      Size
================================================================================
Installing:
 powershell    x86_64    6.2.0-1.rhel.7    packages-microsoft-com-prod     55 M

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

Total download size: 55 M
Installed size: 55 M
Downloading packages:
warning: /var/cache/yum/x86_64/7Server/packages-microsoft-com-prod/packages/powershell-6.2.0-1.rhel.7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for powershell-6.2.0-1.rhel.7.x86_64.rpm is not installed
powershell-6.2.0-1.rhel.7.x86_64.rpm                       |  55 MB   00:10
Retrieving key from https://packages.microsoft.com/keys/microsoft.asc
Importing GPG key 0xBE1229CF:
 Userid     : "Microsoft (Release signing) "
 Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
 From       : https://packages.microsoft.com/keys/microsoft.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : powershell-6.2.0-1.rhel.7.x86_64                             1/1
  Verifying  : powershell-6.2.0-1.rhel.7.x86_64                             1/1

Installed:
  powershell.x86_64 0:6.2.0-1.rhel.7

Complete!
[tuyendq@rhel1 ~]$

Let's start powershell by running pwsh command and check system up time with new Get-Uptime cmdlet

[tuyendq@rhel1 ~]$ pwsh
PowerShell 6.2.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/tuyendq> Get-Uptime

Days              : 93
Hours             : 11
Minutes           : 47
Seconds           : 55
Milliseconds      : 0
Ticks             : 80776750000000
TotalDays         : 93.4916087962963
TotalHours        : 2243.79861111111
TotalMinutes      : 134627.916666667
TotalSeconds      : 8077675
TotalMilliseconds : 8077675000


PS /home/tuyendq>

Check Powershell version by echoing built-in variable $PSVersionTable

PS /home/tuyendq> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Linux 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov …
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /home/tuyendq>

Popular posts from this blog

Linux command: lspci

Linux command: lspci - list pci devices tuyendq@ubuntu001:~$ man lspci NAME        lspci - list all PCI devices SYNOPSIS        lspci [options] DESCRIPTION        lspci is a utility for displaying information about PCI buses in the system and devices connected to them.        By  default,  it  shows a brief list of devices. Use the options described below to request either a more verbose output or output intended for parsing by        other programs.        If you are going to report bugs in PCI device drivers or in lspci itself, please include output of "lspci -vvx" or even better  "lspci  -vvxxx"  (however,        see below for possible caveats).        Some  parts of the output, especially in the highly verbose modes, are probably intelligible only to experienced PCI hac...

Linux command: lastlog

lastlog command reports the most recent login of all users or of a given user. NAME lastlog - reports the most recent login of all users or of a given user SYNOPSIS lastlog [options] DESCRIPTION lastlog formats and prints the contents of the last login log /var/log/lastlog file. The login-name, port, and last login time will be printed. The default (no flags) causes lastlog entries to be printed, sorted by their order in /etc/passwd. OPTIONS The options which apply to the lastlog command are: -b, --before DAYS Print only lastlog records older than DAYS. -h, --help Display help message and exit. -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. -t, --time DAYS Print the lastlog records more recent than DAYS. -u, --user LOGIN|RANGE Print the ...

DOS Commonly Used Commands