Getting Started with PowerShell 6.0 in Linux [Beginner Guide]

After Microsoft falling in love with Linux (what has popularly come to be known as “Microsoft Loves Linux”), PowerShell which was originally a Windows-only component, was open-sourced and made cross-platform on 18 August 2016, available on Linux and Mac OS.

PowerShell is a task automation and configuration management system developed by Microsoft. It is made up of a command language interpreter (shell) and scripting language built on the .NET Framework.

It offers complete access to COM (Component Object Model) and WMI (Windows Management Instrumentation), thereby allowing system administrators to carry out administrative tasks on both local and remote Windows systems as well as WS-Management and CIM (Common Information Model) enabling administration of remote Linux systems plus network devices.

Under this framework, administrative tasks are fundamentally carried out by particular .NET classes called cmdlets (pronounced command-lets). Similar to shell scripts in Linux, users can build scripts or executables by storing groups of cmdlets in files by following certain rules. These scripts can be used as independent command line utilities or tools.

Install PowerShell Core 6.0 in Linux Systems

To install PowerShell Core 6.0 in Linux, we will use official Microsoft Ubuntu repository that will allows us to install through most popular Linux package management tools such as apt-get and yum.

On Ubuntu 16.04

First import the public repository GPG keys, then register the Microsoft Ubuntu repository in APT package sources list to install Powershell:

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
$ sudo apt-get update
$ sudo apt-get install -y powershell

On Ubuntu 14.04

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
$ sudo apt-get update
$ sudo apt-get install -y powershell

On CentOS 7

First register the Microsoft RedHat repository in YUM package manager repository list and install Powershell:

$ sudo curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/microsoft.repo
$ sudo yum install -y powershell

How to Use Powershell Core 6.0 in Linux

In this section, we will have a brief introduction to Powershell; where we will see how to start powershell, run some basic commands, look at how to work with files, directories and processes. Then later dive into how to list all available commands, show command help and aliases.

To start Powershell, type:

$ powershell
Start Powershell in Linux

Start Powershell in Linux

You can check the Powershell version with the command below:

$PSVersionTable
Check Powershell Version

Check Powershell Version

Running some basic Powershell commands on Linux.

get-date          [# Display current date]
get-uptime        [# Display server uptime]
get-location      [# Display present working directory]

Working with Files and Directories in Powershell

1. Create a new empty file using the two methods below:

new-item  tecmint.tex
OR
“”>tecmint.tex

Then add content to it and view the file content.

set-content tecmint.tex -value "TecMint Linux How Tos Guides"
get-content tecmint.tex
Create New File in Powershell

Create New File in Powershell

2. Delete a file in powershell.

remove-item tecmint.tex
get-content tecmint.tex
Delete File in Powershell

Delete File in Powershell

3. Create a new directory.

mkdir  tecmint-files
cd  tecmint-files
“”>domains.list
ls
Create Directory in Powershell

Create Directory in Powershell

4. To perform a long listing, which displays details of a file/directory including mode (file type), last modification time, type:

dir
Directory Long Listing in Powershell

Directory Long Listing in Powershell

5. View all running processes on your system:

get-process
View Running Processes in Powershell

View Running Processes in Powershell

6. To view details of a single/group of running processes with a given name, provide the process name as an argument to the previous command as follows:

get-process apache2
View Specific Process in Powershell

View Specific Process in Powershell

Meaning of the units in the output above:

  1. NPM(K) – amount of non-paged memory that the process is using, in kilobytes.
  2. PM(K) – amount of pageable memory that the process is using, in kilobytes.
  3. WS(K) – size of the working set of the process, in kilobytes. The working set consists of the pages of memory that were recently referenced by the process.
  4. CPU(s) – amount of processor time that the process has used on all processors, in seconds.
  5. ID – process ID (PID).
  6. ProcessName – name of the process.

7. To know more, get a list of all Powershell commands for different tasks:

get-command
List Powershell Commands

List Powershell Commands

8. To learn how to use a command, view its help page (similar to man page in Unix/Linux); in this example, you can get help for the Describe command:

get-help Describe
Powershell Help Manual

Powershell Help Manual

9. view all available command aliases, type:

get-alias
List Powershell Command Aliases

List Powershell Command Aliases

10. Last but not least, display command history (list of commands you had run previously) like so:

history
List Powershell Commands History

List Powershell Commands History

That’s all! for now, in this article, we showed you how to install Microsoft’s Powershell Core 6.0 in Linux. To me, Powershell still has a very long way to go in comparison to the traditional Unix/Linux shells which offer, by far better, more exciting and productive features to operate a machine from the command line and importantly, for programming (scripting) purposes as well.

Visit Powershell Github repository: https://github.com/PowerShell/PowerShell

However, you can give it a try and share your views with us in the comments.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

25 Responses

  1. Shivangi Jena says:

    I am trying to work with SCOM, running the powershell script from Linux server.

    Here is the error :

    [[email protected] TEST]# pwsh MM.ps1
    Checking if OperationsManager Module is loaded
    Importing OperationsManager Module
    Import-Module : The specified module 'OperationsManager' was not loaded because 
    no valid module file was found in any module directory.
    Powershell Version: powershell-6.1.3
    At /tmp/TEST/MM.ps1:25 char:1
    + Import-Module OperationsManager -ErrorAction Stop
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (OperationsManager:String) 
    [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.
    PowerShell.Commands.ImportModuleCommand
    

    How to install the Operationmanager module in Linux so I be able to fire SCOM commands. I don’t see any document for Linux but plenty of them for windows.

  2. thedarlingsounds.Tumblr.com says:

    I got this website from my pal who told me regarding this web page and now this time I am visiting this web site and reading very informative articles at this place.

  3. Sylvio kaufmann says:

    I am with you Elio…

    Powershell on Linux / OSX is designed for cross-platform solutions

    so far you can create scripts they are running on all casual operating systems without the need to create a scripts in different languages for every os.

    this will make much things easier to handle without the knowledge of different scripting languages.

    between the main reason for developing ps on Linux is the “Microsoft azure switch” which connects the cloud with the local network. its an 100% based Linux developed from Microsoft and they don’t want to force windows administrators in more Linux then needed.

    and the project ps on Linux is much older than most of the people are thinking…its no idea of Microsoft…this project was born by Linux developers years ago.

    • Eddie G. says:

      I dunno about that last statement. According to this? Powershell started and was built by Microsoft:

      https://en.wikipedia.org/wiki/PowerShell

      And according to this page, which is ALSO from Microsoft, they were the ones to bring Powershell to Linux

      https://msdn.microsoft.com/powershell

      https://blogs.msdn.microsoft.com/powershell/2016/08/18/powershell-on-linux-and-open-source-2/

      not the other way around. most Linux users are NOT fans of Microsoft, so it stands to reason that they’re not fans of it’s products nor anything that tries to “muddy the waters” of the two. Trust me. I know. I’ve been using Linux since ’03 and I don’t relish nor look forward to any kind of mixing of the two platforms.

      Are there actual business use-cases for it? I’m sure there are, but those who have all-Linux shops…will have very little use for this since they’re already built out the way they want or need to be. Honestly? this still feels like more “Microsoft-ery” to try and get the masses to believe that there’s some deep seated love that’s been there for years.

      While Satya might have the right mindset?….there are still pending “patent” lawsuits that MS is currently attacking the open source and Linux community with. Until those ALL go away?…then nothing MS does will be considered as authentic and real.

      Hopefully someone will point this article out to the MS bigwigs and they’ll take to handling their legal side before they continue to try and make nice with open source. If you speak to a lot of Linux SysAdmins?….you’ll hear the same tone in all their replies / emails / IM messages / phone calls etc.

      There’s just no reason to be blending these two. A lot of times….when you make mention of the whole MS loves Linux topic?…..their reply will be “Why?”…..its just a case of “Too Little Too Late”….when Linux was ready, willing and able to play nice with MS they went in the opposite direction.

      Now that Open Source Software is just about EVERYWHERE?…..that’s the time MS wants to be friends?…well now we already HAVE our own Terminals…our own syntax…..our own apps and programs and also there are ways to get MS without having to install anything that will “attach” itself. (Thank god for Oracle’s VirtualBox….VMWare…and XenServer!) on the other side you have PlayOnLinux…or WINE…..

      • Aaron Kili says:

        @Eddie

        This is so interesting, ” most Linux users are NOT fans of Microsoft, so it stands to reason that they’re not fans of it’s products nor anything that tries to “muddy the waters” of the two. Trust me. I know. I’ve been using Linux since ’03 and I don’t relish nor look forward to any kind of mixing of the two platforms. ”

        This has happened to me too, ever since i switched to Linux, using Windows and other Microsoft products has been become undesirable, unless when forced to, due to unavoidable situations.

        However, the existence of the two platforms has been beneficial to the respective users out there, though the primary purpose/motive(commercial vs free, closed vs open source) of why they currently exist differs. But the a user will always choose, for what ever reason.

        Thanks for sharing your thoughts once again.

      • Sylvio kaufmann says:

        This was a answer i was expecting from Linux admins they don’t want to deal with Microsoft ^^

        In this post topic was powershell on Linux and the first time i ever heard of this was the project called pash for Linux and this project started 2012 by searching members for developing on github.

        For sure its late for the topic cooperation of Linux and windows but the last years both sides where unable to accept the others and both sides doesn’t wanted to do so, the Linux guys always wanted to be separated from windows, now the time has come to think new about it but none wants that as you say:

        “Now that Open Source Software is just about EVERYWHERE?…..that’s the time MS wants to be friends?…well now we already HAVE our own Terminals, our own syntax, our own apps and programs and also there are ways to get MS without having to install anything that will “attach” itself. (Thank god for Oracle’s VirtualBox, VMWare and XenServer!) on the other side you have PlayOnLinux or WINE”

        Between why you don’t like the patents on Microsoft software?…i really think its okay in cause of the following in 95% of all cases modified open source projects will not be published as the license says and for sure.

        When i spend months of time into a program i don’t want that anyone can take the code and build something with it to earn money and i don’t have something for this than “really useless fame behind a nickname where nobody knows my real name and so on” in this case every changes of every open source software should be available on the INTERNET…LOL you can forget about that…

        Everyone just wants the good points of open source not the bad points. in this double edged sword 99,9% of all pepple always forgot about the darkside of this and in 99,9% of all cases you could get the code but you never will recognize what the code is doing without being a professional developer

        So it doesn’t matter if you can read a book when you don’t understand the language, most of the open source junkies are miles away from understand the codes they can download!!! so its no worthy for them else the point…”its for free for me”. thats the point why Linux distributions has grown as much in the last few years.

        At the other side there is the bash on windows which do exactly the same shit for the Linux guys to take care of windows in their “language”…none in the ms sector cries about it…they think this is amazing…but there is cry in the Linux sector about powershell.

        I don’t understand why I use both systems and I am happy that the future will be powershell for all systems and for sure no really big environment is build as homogenius network. in most of the cases the administrators are forced to be informed and skilled in both worlds…so why the hell a similar language would be shitty?

        Microsoft wants to expand into the Linux sector and i don’t want to say that this is worse…

        Surely this will change much in the it-world but changes are unstoppable and the edge between windows and Linux will be vanish the next years in cause of the cooperation of canonical and Microsoft and this cooperation will go on as long this Indian is ceo at Microsoft and canonical earns money via this. even software developers in the Linux sector are interested in this.

        so the opinion of the end user is totally worthless and its useless to cry about!

        get it into your head and educate yourself or you will get outdated.

        • Eddie G says:

          You mistake me stating facts as complaining. Understand. The reason why Microsoft “Loves” Linux? is because they’re losing share in the business sector, as the databases that were once MS SQL are now MariaDB, NoSQL, or PostgreSQL.

          The file servers and print servers that were scheduled to be Windows Server 2012 / 2016 etc? are being converted or are being built out as Linux servers. (I’m not asking, I work for one of the biggest online “stores” and they’re 98.9% Linux servers.)

          So it’s not about crying, its about asking the age old question: “If it ain’t broke…..why fix it?”. The whole powershell topic is almost a moot point, there are those businesses that will adopt it and use it and those that won’t thank goodness we’ve already been told we WON’T be moving in that direction at all!

          For the ones who want it? most open source is available to them and will run on their hardware. You already know there are “limitations” when it comes to running Windows on older or legacy hardware. The points you state about open source and bad points.

          Understand, what one person considers a negative someone else might consider a positive, but be that as it may NO operating system is perfect. And while Linux may have it’s flaws? Microsoft has proven throughout the decades to be unworthy of calling itself a secure system, with the amount of trojans, viruses, malware, adware, and even ransomware that is designed to break it?

          Its not something you can rely on, at least for long term. The powershell issue is just another way for MS to “creep” into the open source communities and “dig in”. Go lookup “patent lawsuits” of MS vs Linux and tell me how can a company that claims to love you be trying to SUE you at the SAME TIME!?

          Why is no one speaking on that? No its all just “Wow…Microsoft is a Linux Foundation supporter now…they MUST have nothing but good intentions right?” yeah keep telling’ yourself that. And good luck if things go sour between them.

          As for me? I’ll stick with what I know, it works, its compatible with everything we use, we’ve hired people that KNOW the language and there’s no reason to fiddle with things. Accept the fact that not everyone is thinking like you do….just as I accept that not everyone will think like me.

          • Sylvio kaufmann says:

            I accept your opinion but did you ever realized that most viruses are not written to infect Linux systems because of the possibility to get useable they are sellable is much lower. WHY? i can tell you…viruses in the last time where always viruses they have to “activate” by the target itself…last ransomwares for example where all in makros the user have to accept the start…LOL this also can happen to you if you are stupid as hell as the windows users they have done that. most of the hackers are on search of the stupid…and stupidness the best operating system can not be undone…by the way check metasploit database for Linux exploits…you will drop out of your cloud ^^

            https://www.exploit-db.com/

            there are also viruses like locky for Linux systems and if you feel safe you where wrong when you look at the “exploit shellcode archive” 5/7 of the last 2 weeks are hacks for Linux…so forget about your opinion only windows is unsecure…

            exploits and viruses in most cases use code that is attacking not the kernel…in most cases third party programs are used to get access to the wanted data. so the securest kernel not saves you when your third party application got hacked.

            and your opinion about stalking from ms into the open source community…perhaps your right BUT…powershell is open source if your right that the community can understand the code they would find something that this is happening and Microsoft would lose his face for years but i don’t think this will happened.

          • Sylvio kaufmann says:

            The main reason for virus alarms on the internet is the stupidness of the most windows users they got problems with viruses in the past. for Linux its recommended to have some skills and know what you do.

            so the possibility to manually activate the viruses in macros is much lower then in windows and the other point is who uses free software? in many cases the users they haven’t got or don’t want to spend the money for software.

            So the possibility to get sellable data is much lower. so use to expense is not given in this case…hackers in the Linux sector in most cases are searching for exploits in Java or flash to be successful.

    • Aaron Kili says:

      @Sylvio

      Thanks for stopping by, and sharing these helpful thoughts.

  4. Martin R.A. says:

    @Eddie – Virtualization , Cloud computing :

    In my opinion Azure must be the main reason for Microsoft to embrace Linux and make SqlServer and powershell available on Linux. Looking on the rising percentage of Linux instances deployed into the different cloud offers, Microsoft MUST make this move to stay in the market.

    I have been doing Unix/Linux myself for many years and we should be glad to see the possibilities to compute without a Graphic head to operate since Windows server 2012.
    Microsoft windows have gone back to its ancestor VMS/OpenVMS and is enabling us to build test environments on Linux as well.

    Regards Martin R.A. – DK

    • Eddie G. says:

      @Martin R.A. – I’ve no doubt there’s an actual business case for this, from the cloud and Azure to containers and database manipulation. I was merely trying to point out that just because MS is giving “bits and pieces” of itself away, does NOT make them some holistic, and benevolent corporation that has the best interests of open source in mind.

      I agree with you that they’re jumping on this bandwagon to gain financial supremacy. And that’s the caveat, while the devs and sysadmins can “play” with this all they want, they should be remembering that MS has a “bad habit” of warming up to a company an then when everything is “champagne & roses” they literally wipe that company / IP / corporation out.

      Or else they just buy it and then dump it somewhere in the woods so it can die.Better to reject this “blending” for production environments….and keep it in the world of virtualizations and “not quite real” servers.

    • Aaron Kili says:

      @Martin

      According to what you have explained here- “In my opinion Azure must be the main reason for Microsoft to embrace Linux and make SqlServer and powershell available on Linux. Looking on the rising percentage of Linux instances deployed into the different cloud offers, Microsoft MUST make this move to stay in the market.”

      Surely, Azure the popular cloud computing platform and services with 38 Azure regions, more than any cloud provider is perhaps the main reason why Microsoft Loves Linux.

      Many thanks for the feedback.

  5. Eddie G. says:

    Being a longtime user of Linux, there’s no logical reason for this to even happen. I for one don’t use Powershell, and I have already mastered the Linux Command line. Why on Earth would I want to get this intertwined on my Linux systems that run so smoothly now? Nope.

    Leave this for those who might want to tinker with it and (possibly) break something that might require a complete re-install. The pro’s who “know”?….will avoid this like the Black Plague.

    Not Related….The Again….Maybe It Is?

    Its amazing to me that years ago, people who used Linux were reviled, shunned and made fun of. That is you didn’t have some sort of Microsoft certification you were “nobody”. That you were considered a Master if you could do things using the “cmd.exe” program.

    There was a time when if you tried to introduce Linux to your Windows systems you were blocked at every turn. You’d see articles and forums where people would ridicule you, call you names, and there would be all manner of arguments about why that “trash” called Linux should stay in it’s own backyard, and leave the “professionals” to do REAL work with Windows.

    Times have changed, to the point where the one company that was trying to stomp Linux out is embracing it as a friend!?. (be careful where that may lead!) I don’t need Powershell or anything else MS has to offer.

    We tried to play nice back then and the refused to, and that kind of forced the various developers to design their own work-arounds for things. Now that Linux is a self-contained, fully functional, OS that can hold its own….NOW you want to come over and act nice? Not buying it or falling for that. We here in Linux-land are ok….take your Powershell and go home. We don’t have any problems with that.

  6. Sparsh Gupta says:

    I have been following Tecmint blogs since past few months now. Although the articles and blogs help me learn new things and master my skills, I always get disappointed because ther’s no pdf’s for the same to download and print it or to keep it for later use. :(

  7. Joseph C Pietras says:

    Did not work for me on Ubuntu 16.04. First steps worked but then got this,

    nas:~ root# apt-get install install
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package install`
    
    • Aaron Kili says:

      @Joseph

      You have used a wrong command, instead type the following after adding the repositories and updating packages’ sources list:

      apt-get install powershell
      OR
      apt-get install -y powershell to answer yes, automatically while installing.

      • Joseph C Pietras says:

        Ouch! Aaron you are correct and changing the command to “apt-get” instead of “apt” worked. Not sure why. In fact, when I ran the apt-get command to install powershell the output said to run “apt autoremove” in order to clean up some no longer needed packages.

        Also the apt documentation (apt –help; man apt) says it is a better front end to apt-get. I have not drilled into all the differences between the two commands.

  8. Elio Panting says:

    Well, you’ll need to understand that powershell for Linux, still in alpha version and as you pointed out, still a lot of work when compared to other Linux shells, powershell offers work with different platforms, the same code and scripts, works across, Linux, windows, OSX and powershell its an object-oriented programming language.

    If you try powershell on windows (full version) you’ll feel that its by far better, more exciting and productive features to operate a machine from the command line and importantly, for programming (scripting) purposes as well than it Linux counterparts.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.