Scripts

How to setup PowerShell on a Linux server

setup PowerShell

As we know, PowerShell is a cross-platform task automation and configuration management framework from Microsoft built on top of the .NET Common Language Runtime; it accepts and returns .NET objects. It consists of a command line shell and an associated scripted language. Powershell enables management of both local and remote linux machines

INSTALLING POWERSHELL ON CENTOS.
-Since the PowerShell package is not included in the official CentOS repository, first thing to do in the installation process is to add the repository with the following command;

curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
Linux server

After adding the repo, use the yum makecache to update the repository cache

PowerShell installation

Now install the powershell with yum install powershell

PowerShell installation
Linux PowerShell

Along the line, the installation guide may ask you to accept the gpg key. Type y to continue the installation.

setup PowerShell

Here are a few commands you can run to check if the installation is well set up;

pwsh –v

this will tell you the version of powershell  you have just installed.

Linux server
pwsh

This will take you to the powershell terminal and you will be ready to run powershell commands

Similarly, you can run Linux commands from the powershell terminal.

MAKING YOUR LOGIN POWERSHELL
– Run the whoami command to find the path of the pwsh shell program. Use that result of the command to set the default login shell to that of the powershell with the following command;

usermod –s /usr/bin/pwsh $(whoami)

Now reboot your machine and that is all that is needed to have PowerShell up and running.

I hope you found this blog post helpful. If you have any questions, please let me know in the comment session. I welcome you to follow me on Twitter and Facebook.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x