Install Powershell on Linux/CentOS

Background

Back playing around with a Linux box and wanted to see if it is any easier for me to understand the steps for installing Powershell.

Outline

  1. Configure Source Repositories
  2. Redhat Repository – Local
    • Review “Local” Redhat Repository
      • Is Microsoft repository registered?
    • If Microsoft Repository is not registered, please register it
      • Locally, Register Microsoft Repository
  3. Install Powershell

Tasks

Configure Source Repositories

Review available Microsoft Repository for OS/Version

Listing

  1. packages
  2. Redhat
    • version
  3. Prod Repo

Images

packages.microsoft.com

package.microsoft.0123AM

packages.microsoft.com.config.rhel.8

package.microsoft.prod.01.20200518.0120AM

packages.microsoft.com.config.rhel.8/prod.repo

package.microsoft.prod.repo.01.20200518.0124AM

Register Microsoft Repository – Local

curl/tee

Syntax
curl [url-repo] | sudo tee /etc/yum.repos.d/[filename]

Sample
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
Output
Output – Image
package.microsoft.prod.repo.register.01.20200518.0135AM
Output – Text

>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   1707      0 --:--:-- --:--:-- --:--:--  1707[sudo] password for dadeniji:

[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
>

Explanation
  1. Downloaded and Saved Microsoft Repository

Review Locally Registered Repository

grep

Syntax
grep -i [pattern] [file]

Sample

grep -i 'microsoft' /etc/yum.repos.d/*.repo

Output
Output – Image
grep.01.20200518.0141AM
Output – Text

>grep -i 'microsoft' /etc/yum.repos.d/*.repo
/etc/yum.repos.d/microsoft.repo:[packages-microsoft-com-prod]
/etc/yum.repos.d/microsoft.repo:name=packages-microsoft-com-prod
/etc/yum.repos.d/microsoft.repo:baseurl=https://packages.microsoft.com/rhel/7/prod/
/etc/yum.repos.d/microsoft.repo:gpgkey=https://packages.microsoft.com/keys/microsoft.asc
>
Explanation
  1. In etc/yum.repos.d/microsoft.repo
    • Validate entries for Microsoft Repository

Install Powershell

yum

yum – install

Syntax
sudo yum install [package]

Sample
sudo yum install -y powershell
Output
Output – Image -01

yum.install.01.20200519.0145AM

Output – Image -02

yum.install.02.20200519.0145AM

Explanation
  1. Installed
    • powershell-7.0.1-1.rhel.7.x86_64

Validate Powershell

pwsh

helloWorld

Syntax
pwsh -Command "Write-Host 'hello'"

Sample
pwsh -Command "Write-Host 'Hello $(whoami)'"
Output
Output – Image -01

lab.helloWorld.01.20200518.0157AM

Explanation
  1. We invoked Powershell
    • pwsh
  2. Using -Command
    • Sent along a payload
  3. Payload
    • Write-Host ‘Hello $(whoami)’

References

  1. Microsoft
    • Docs
      • Configure repositories for installing and upgrading SQL Server on Linux
        Link
      • Installing PowerShell on Linux
        Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s