PowerShell and Linux

Now that PowerShell is open source and available on Linux, I went ahead and adventure to see what cmdlets are available on Linux. Let me show step by step on how to install PowerShell on a RHEL 7 machine and play with some cmdlets.

  1. Make sure wget or curl is installed using  “sudo yum install wget”
  2. You can go to the PowerShell GitHub to download the rpm files. I had to do this because the yum repo did not have the package available PowerShell 


  3. The centOS 7 package works on RHEL and CentOS without problems. Make sure to get link to download the package
  4. If yo go to here https://github.com/PowerShell/PowerShell/releases/tag/v6.0.0-alpha.9 you can get url to download the package


  5. Right click and copy the link
  6. Now the fun login to your RHEL an/or CentOS machine.
  7. Download the PowerShell rpm4

    wget ‘https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.9/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm’


  8. If you try to install the package you will get the following error4.pngthe package have a dependency on linunwind. To install the package run the following command      sudo yum install libunwind

  9. Now lets install PowerShell5the command that to install powershell is

    sudo rpm -ivh powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm


  10. Let’s open the shell by typing sudo powershell6
  11. Lets discover PowerShell. The first thing I did was to check how many cmdlets are available and run update-help 7I think, I will never be able to write  a script  without seeing red 🙂 . Right now there are 345 cmdlets available on Linux but I guess this number will increase quickly overtime.
  12. The second command I ran was the famous write-host, and it actually works8Something pretty cool is that auto-complete works, but it works in a different way. It will print all the options you have on the screen instead of using tab complete until you find the command or parameter you want.
  13. I wanted to find out the amount of free space on the drive. On Linux you will run df and an easy way to do it in PowerShell is using get-psdrive9The beauty about this is that df works and get-psdrive works also and you can decide what command to use when you need to find out how much free space you have
  14. Pipe  from a linux command to a PowerShell command works.1As you can see we can use a linux native command and pipe to Out-file. Auto completion also works to find where to put a file  and get-content will display the content on the screen as it does on Windows.
  15. Get-Process works the same in Linux as in Windows. If you want to find out the top 5  processes and sort it descending run the following

    Get-Process | Sort-Object CPU -Descending | Select-Object -First 52


  16. Execution policy does not work on Windows. if you run Get-ExecutionPolicy you will get Unrestricted but if you run Set-ExecutionPolicy  -ExecutionPolicy RemoteSigned. The message is clear  “Operation is not supported on this Platform”1
  17. It seems that the cmdlet stop-process does not work on linux1
  18.  Now lets do a performance test
    The scenario is simple. I am going to print the number 1 to 20,000 on the screen using  PowerShell on Windows 10 and PowerShell on RHEL 7 machine. The Linux machine will have less resources available.
    RHEL Machine               2 vCPU and 4GB of RAM
    Windows 10 Machine   4vCPU and 4GB of RAM$a = 1..20000

    Measure-Command {Write-Output $a | Out-Default}


    Windows took 5 seconds
    Linux took 1 second

    As you can see PowerShell on Linux is faster than PowerShell on Windows. Of course more tests need to be done but this is a start.


3 Replies to “PowerShell and Linux”

  1. just for fun, tried your performance run on dualboot machine, 517 ms on Mint18, 198 ms on Win10


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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