How to install PowerShell on CentOS 7
How to install PowerShell on CentOS 7
Powershell is a terminal application for windows system such as windows 8 and windows 10. It can be used as a command line interface for windows system. PowerShell can also be installed on a Linux machine. In this article, you will learn about the installation procedure of PowerShell.
Installing PowerShell
To install PowerShell, it is necessary to download the package first, so use the following command to download it.
[root@linuxhelp ~]# wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.10/powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm
Once it is downloaded, install it by using yum or rpm command. Here in this example, yum command is used.
[root@linuxhelp ~]# yum install powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm -y
Loaded plugins: fastestmirror, langpacks
Examining powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm: powershell-6.0.0_alpha.10-1.el7.centos.x86_64
Marking powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package powershell.x86_64 0:6.0.0_alpha.10-1.el7.centos will be installed
--> Processing Dependency: libunwind for package: powershell-6.0.0_alpha.10-1.el7.centos.x86_64
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 155 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 121 kB 00:00:04
(3/4): updates/7/x86_64/primary_db | 2.2 MB 00:00:11
(4/4): base/7/x86_64/primary_db | 5.6 MB 00:00:23
Determining fastest mirrors
* base: mirror.fibergrid.in
* extras: mirror.fibergrid.in
* updates: mirror.fibergrid.in
--> Running transaction check
---> Package libunwind.x86_64 2:1.1-5.el7_2.2 will be installed
--> Finished Dependency Resolution
.
.
.
Installed:
powershell.x86_64 0:6.0.0_alpha.10-1.el7.centos
Dependency Installed:
libunwind.x86_64 2:1.1-5.el7_2.2
Complete!
PowerShell is installed, launch it with the help of following command.
[root@linuxhelp ~]# powershell
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
If you want to view the list of the commands, you can use the following command inside the PowerShell terminal. It displays top 10 (alphabetical order) of the list.
PS /root> (Get-Command)[0..9]
CommandType Name Version Source
----------- ---- ------- ------
Function Add-NodeKeys 0.0 PSDesiredStateConfiguration
Function AddDscResourceProperty 0.0 PSDesiredStateConfiguration
Function AddDscResourcePropertyFromMetadata 0.0 PSDesiredStateConfiguration
Function AfterAll 3.3.9 Pester
Function AfterEach 3.3.9 Pester
Function Assert-MockCalled 3.3.9 Pester
Function Assert-VerifiableMocks 3.3.9 Pester
Function BeforeAll 3.3.9 Pester
Function BeforeEach 3.3.9 Pester
Function cd..
Use following command, To view the current working directory.
PS /root> pwd
Path
----
/root
To list files and directory, you can use ls command or dir command as shown below.
PS /root> ls anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Public Videos Desktop Downloads Music powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm Templates PS /root> dir Directory: /root Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2/2/17 1:26 PM Desktop d----- 2/2/17 1:26 PM Documents d----- 2/2/17 1:26 PM Downloads d----- 2/2/17 1:26 PM Music d----- 2/2/17 1:26 PM Pictures d----- 2/2/17 1:26 PM Public d----- 2/2/17 1:26 PM Templates d----- 2/2/17 1:26 PM Videos ------ 2/2/17 6:47 PM 1505 anaconda-ks.cfg ------ 2/2/17 1:26 PM 1556 initial-setup-ks.cfg ------ 2/2/17 11:51 AM 40410715 powershell-6.0.0_alpha.10-1.el7.centos.x86_64.rpm
If you want to move to specific directory path, use the following command.
PS /root> cd ./Desktop/
In order to move to the home directory, run the following command.
PS /root/Desktop> cd
You can list all the content of a particular directory with the help of the following command.
PS /root> Get-ChildItem /
Directory: /
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----l 2/2/17 6:34 PM bin
d-r--- 2/2/17 6:47 PM boot
d----- 2/2/17 1:26 PM dev
d----- 2/2/17 2:08 PM etc
d----- 2/2/17 6:46 PM home
d----l 2/2/17 6:34 PM lib
d----l 2/2/17 6:34 PM lib64
d----- 6/10/14 5:41 AM media
d----- 6/10/14 5:41 AM mnt
d----- 2/2/17 2:08 PM opt
d-r--- 2/2/17 6:54 PM proc
d-r--- 2/2/17 2:06 PM root
d----- 2/2/17 2:08 PM run
d----l 2/2/17 6:34 PM sbin
d----- 6/10/14 5:41 AM srv
d-r--- 2/2/17 6:54 PM sys
d----- 2/2/17 2:09 PM tmp
d----- 2/2/17 6:34 PM usr
d----- 2/2/17 1:26 PM var
If you want to create new file in the PowerShell terminal, use the following command.
PS /root> New-Item -Path test.txt
Directory: /root
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 2/2/17 2:14 PM 0 test.txt
Use the following command to create a new directory.
PS /root> New-Item -ItemType Directory -Path newdir
Directory: /root
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/2/17 2:15 PM newdir
In order to view the content of a file, use the following command.
PS /root> Get-Content anaconda-ks.cfg
#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable
.
.
.
@multimedia
@print-client
@x11
%end
Use the following command to rename a file.
PS /root> Move-Item test.txt sample.txt
Use the following command to copy a file.
PS /root> Copy-Item sample.txt copy.txt
Use the following command to remove a file.
PS /root> Remove-Item copy.txt
Use the following command to remove a directory recursively.
PS /root> Remove-Item newdir -Recurse
Comments ( 0 )
No comments available