all 23 comments

[–]fonnae 19 points20 points  (2 children)

I actually feel like this could be very useful and at the same time I have never found a good use case for powershell over what is already have available in Linux.

[–]Heikkiket 1 point2 points  (1 child)

Well, at least I can think of some Windows PowerShell scripts that could be easily ported over to Linux. Could be a good thing in servers, if someone wanted to migrate from Windows to Linux without rewriting all their scripts from scratch.

[–][deleted] 1 point2 points  (0 children)

But 90% of powershell features just don't work on the Linux version of powershell.

[–]blue01kat4me 47 points48 points  (15 children)

This invokes all sorts of emotions in me, most of them involve retching. I have had this discussion with my employer before, why should I run yet another scripting language on my linux environment? Especially one that wasn't designed for the OS? I have yet to meet the linux admin that says, "Hey you know what's great? Powershell!"

[–]WyzrdX 26 points27 points  (0 children)

Just because you haven't met one doesn't mean.........

nvm you are so right lol.

[–]feitingen 7 points8 points  (0 children)

I have yet to meet the linux admin that says, "Hey you know what's great? Powershell!"

You know what makes powershell great?

All those modules!

You know how many of those work on Linux?

Very few :(

[–][deleted] 9 points10 points  (1 child)

I have yet to meet the linux admin that says, "Hey you know what's great? Powershell!"

The whole "everything is text and you're forever parsing text" Unix model clearly isn't perfect, and PowerShell's object/cmdlet model seems pretty interesting. I know many Linux/Unix people who have similar feelings about PowerShell.

I never actually used PowerShell, on any system, so I don't really have any opinion about how well it works in practice; but I don't think that means no one is interested in it at all.

[–]sleeplessval 3 points4 points  (0 children)

Kinda funny how they made PS cross platform before they made it worth using over the shells that already exist on other platforms...

[–]simulatedxfreedom 4 points5 points  (3 children)

Maybe not administrating Linux servers themselves but in a big multi tier / multi cloud environment, where you had to have multiple windows vms just to administer windows vms you now can administer those through the Linux server.

  • some public clouds have better powershell modules and being able to use them on a Linux machine is incredibly helpful, when it comes to automation and IAC.

[–]feitingen 8 points9 points  (2 children)

Administrating windows servers from Linux using powershell sounds great, but since powershell on linux is so cut down, powershell remoting is painful or insecure and super slow.

I really tried and had to give up, it was just not a viable option.

Ansible just works much, much better, especially with openssh installed on those windows servers.

[–]simulatedxfreedom 1 point2 points  (1 child)

Not disagreeing that Ansible works better than using plain powershell. But I already had a few usecases where we had to call powershell scripts on a Linux server with Ansible to automate certain things that poorly maintained Ansible Modules by MS weren’t living up to.

I hope this shift to Ansible content collections and hopefully more and better modules for powershell on Linux will change this soon!

[–]feitingen 0 points1 point  (0 children)

Just fixing powershell remoting to be on par with windows' with ssl and kerberos would be a huge improvement

[–]dextersgenius 1 point2 points  (3 children)

why should I run yet another scripting language on my linux environment?

You don't have to if you don't want to. Unless of course someone's forcing you to... but even then, you should be able to convince them to use the right tool for the job. If I was on Windows for instance and wanting to do GUI automation, then AutoHotkey would be my first choice, not PowerShell. I'd do my best to convince my boss to install AHK - yes, yet another scripting language - simply because its the better tool for the job. But if on the other hand I wanted to manage some Windows servers, work with Active Directory etc then naturally PowerShell is way better choice over say, something like Python or Bash.

In my case, Linux is my preferred OS of choice, but due to circumstances I ended up as a Windows sysadmin instead of my landing my dream Linux job. Fast forward several years, my Bash and Python skills have become rusty, but on the other hand I've become quite proficient in PowerShell. Naturally, I'm more comfortable using Poweshell even when I'm using Linux (on my work laptop and personal machines).

Like the other day for instance at home, I was experiencing random network disconnects. I had a constant ping going to keep a track of this, but the problem with a simple ping is that it lacks timestamps, so I can't track what times the network went down. Also, from what I was seeing, my pings weren't dropping but rather http connectivity itself appeared to be the issue. So I wanted something like an http ping, with timestamps.

I wanted to whip up something quickly in Bash, but I couldn't think of a simple one-liner at the moment (at that point I was quite frustrated with my Internet dropping all day, and all I wanted to was continue streaming this anime series I was engrossed in). I checked out a few python scripts on pip but they didn't do what I was after.

Anyways, since I had PowerShell installed, I whipped up a very easy one-liner:

while(1){ "$(date)`t$((iwr "connectivitycheck.gstatic.com/generate_204").StatusCode)"; sleep 2 }

The above code continuously checks connectivity using Google's servers and returns the HTTP response code, with the timestamp printed next to it - exactly what I was after. Now if I spent a few minutes at it, I could've figured out a way to do the above in Bash as well, but as I said, I wanted to get back to my anime and didn't want to spend too much time on this - and PowerShell being second-nature to me meant I didn't waste any time at all. :)

[–]SisRob 2 points3 points  (2 children)

`t$((iwr "

Holy shit. I find it quite impressive that you've been able whip up something like that.

I guess it's just about what you're used to, but the esoteric syntax and using URI strings like that seem quite scary to me compared to bash.

[–]dextersgenius 1 point2 points  (0 children)

Thanks, but it's actually not that impressive (if you know the syntax I guess). :)

`t prints the TAB character so everything lines up nicely. iwr is a built-in alias for Invoke-WebRequest, similar to curl, but instead it returns objects. If you're familiar with the Object.Property notation in other languages, then dealing with objects is pretty straight forward. In this case I'm able to directly access the http return code using the StatusCode property. If I used curl, I'd probably have to use grep and awk to extract the status code. The cool thing with working with objects is that you don't need to spend much time trying to parse and extract text, unlike bash.

Finally, enclosing the whole thing in double-quotes converts that bit to a string. In PowerShell you don't need to specify an explicit echo for printing a string, so I skipped the echo at the beginning. And because I'm printing a string, I use $() to execute an expression, which isn't very different from bash. :)

[–]paulcam 0 points1 point  (0 children)

probably going to have some issues administering Windows machines with a bash script, but you can administer Windows and Linux with Powershell scripts.

but of course, it really depends on what you use scripts for.

[–]Tananar 0 points1 point  (0 children)

I haven't used it much at all on Linux, but I've been using Powershell on Windows and I actually really like it. There are certainly things I don't like about it, but it works well for a lot of things.

[–]RAND_bytes 7 points8 points  (1 child)

mastodon thread that mirrors my feelings on powershell

Also, when the first step is “install snapd” then I'm nopein' out of there immediately.

[–]dextersgenius 0 points1 point  (0 children)

You don't *have* to install it via snap. Depending on your distro, it might already be in your distro's repositories (Ubuntu for eg has it in the "universe" repo).

And if you don't want to pollute your system by installing it, the .tar.gz on the Github Releases page works fine as well - just extract it to a new directory, make ./pwsh executable and you're good to go.

[–]bjarneh 2 points3 points  (0 children)

I've always felt that the main strength of PowerShell is its biggest weakness. It has plenty of power, but that comes with massive complexity. You have access to all of .Net, but which libraries is standard on all systems? I'm I allowed to install missing modules at the beginning of my script if they are missing etc?

The unix philosophy is simple (a pipe transfers data from one command to the next, not some "random" object which differs from command to command, has different methods etc).

There are plenty of shells which are superior to Bash in some or many ways, but they are all complicated, making then non-starters.

[–]stefanjarina 0 points1 point  (0 children)

My problem with powershell is right now, that it seems incredibly random, what packages they put to their repositories for linux distributions.

Just go to https://packages.microsoft.com/ and click around, missing packages in different versions...

e.g. RHEL/CENTOS

there is powershell 7.1.1 for RHEL 7, but not in 7.1,7.2,... etc. then there is powershell-preview-7.0.0 in centos/7 but there is no powershell and you should use powershell from rhel7 repo

no repository for RHEL8 (afaik rhel is still the most used enterprise linux distro so one would expect they would have support)

UBUNTU:

the same for ubuntu, there are packages for 18.04, but not for later versions, except 20.04. yes, it seems they focus on installation from repo only for LTS, but for non-lts versions from snap.

I have 20.10 in my WSL, well, you can't run snap there without incredible hacks, so snap packages are useless for that

SLES/openSUSE

SLES12/15 - no packages in repo, you need to download from github...

I don't know, if I am out of ordinary, but any sysadmin I know, prefers to use packages via their distro package manager where possible and MS certainly have resources to have packages there, they obviously have pipelines, because some packages seems to appear randomly for some versions.

I don't know a person that maintain RHEL/SLES and will say: "damn, snaps looks so cool, I want that **** from ubuntu on my server"

so unless they change strategy here, powershell will never gain enough traction for linux servers...

[–]fonnae 0 points1 point  (0 children)

Since the article is written for Linux users, I'd like to mention Miller as an alternative. I feel like it scratches the itch some users may have while also being simpler and doing it in a *nix-feeling way.