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
- Configure Source Repositories
- Review available Microsoft Repository for your OS/Version ( https://packages.microsoft.com/config/rhel/ )
- Redhat Repository – Local
- Review “Local” Redhat Repository
- Is Microsoft repository registered?
- If Microsoft Repository is not registered, please register it
- Locally, Register Microsoft Repository
- Review “Local” Redhat Repository
- Install Powershell
Tasks
Configure Source Repositories
Review available Microsoft Repository for OS/Version
Listing
Images
packages.microsoft.com
packages.microsoft.com.config.rhel.8
packages.microsoft.com.config.rhel.8/prod.repo
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
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
- 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
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
- 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
Output – Image -02
Explanation
- 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
Explanation
- We invoked Powershell
- pwsh
- Using -Command
- Sent along a payload
- Payload
- Write-Host ‘Hello $(whoami)’