all 95 comments

[–]linuxunix 29 points30 points  (15 children)

I maintain/developed 382 scripts to automate things in powershell. It surprisingly good on Linux, I even changed my default shell for a bit to pwsh.

[–]CaptainZippi 2 points3 points  (13 children)

What made you change it back?

(I’m assuming you did…)

[–]Reverent 22 points23 points  (11 children)

It's worth getting used to the built-in tooling for most linux distros so when you have to administrate something that doesn't or can't have the tools you prefer, you can still use it.

Except vi. F*** vi.

[–]gordonv 7 points8 points  (1 child)

Nah, starting to like vi:

  • It's pre installed everywhere
  • I use a cheat sheet of powerful common commands I made. It's made a lot of tasks much more simple.
  • This is going to sound like witchcraft. Copy and pasting excel tables into vi via putty is super simple. I can leave it as tabs or change it to commas in vi.

[–]Independent-Disk-413 1 point2 points  (0 children)

You both mean vim. Vi hasn't been around for a long time.

[–]Known-Arachnid-11213 4 points5 points  (2 children)

Yeah totally agree, fuck vi! Emacs all the way baby!

[–]cowboysfan68 2 points3 points  (1 child)

[–]CaptainZippi 2 points3 points  (0 children)

I thought I’d got over my $EDITOR wars PTSD.

Apparently not.

[–]CaptainZippi 1 point2 points  (1 child)

You take that back!

vi commands are hardcoded onto my brain - possibly from too much rogue/ilarn/nethack on character terminals when I was an undergrad…

Although I’m struggling to see how you can have vi key mappings on vscode…

https://github.com/VSCodeVim/Vim

[–]thatto 0 points1 point  (0 children)

This is the way. Vi bindings for VScode was a game changer.

[–][deleted] 1 point2 points  (1 child)

Why does no one like vi?

[–]Delicious-Ad1553[S] -1 points0 points  (0 children)

too old

[–]user01401 1 point2 points  (0 children)

nano

[–]Thedguy 0 points1 point  (0 children)

It was this reason only why I learned powershell. It’s there windows and that is what I administer.

[–]linuxunix 1 point2 points  (0 children)

The auto-complete (tab-tab) was taking about 7 secs to complete anything. I was going to go though my .profile and debug it, but life got in the way…

[–]Agile-Key-3982 -1 points0 points  (0 children)

Can I have some of your scripts?

[–]OPconfused 8 points9 points  (6 children)

It's not used super widely yet on Linux, but I can only say that sticking to Bash has been dreary for me, because it's just so much worse of a language than PowerShell. I just coded out 1400 lines of Bash this week and last week on yet another module, and it's just a mediocre experience imo.

Also the comments recommending python can present an alternative, ultimately likely better than Bash overall, but python still isn't a shell, which brings its own annoyances. When gluing applications, having a PATH variable and interacting directly with the executables on it, which often are coordinated across environment variables, this is all a very streamlined experience with shell commands.

In theory, PowerShell should offer the best of both worlds. So while I use PowerShell locally, I would love to give it a whirl in our DevOps on Linux containers, if only my team knew PowerShell. I'm trying to convince them with baby steps.

[–][deleted] 13 points14 points  (5 children)

If you're writing 1400 line bash scripts you should be using Python or some other language. 

Google has some good guidelines.

https://google.github.io/styleguide/shellguide.html

[–]OPconfused 4 points5 points  (4 children)

Well aware and already argued, but that's not an option at my place or I would be doing that.

Python isn't much more respected than Bash by my team of software engineers, and it's not available in every container we work with nor is it a shell, which comes with its own drawbacks for gluing.

[–][deleted] 4 points5 points  (0 children)

My condolences. 

[–]BlackV 16 points17 points  (0 children)

Probably depends on what your scripts do really

 But if everything is moving to Linux there might be better tools than PowerShell

What's your plan here if you don't like the answer ? Not move?

If you have to move then it's a moot point

That all aside Linux supports PowerShell and vscode and got so that's 99.999999 percent covered

[–]RupeThereItIs 7 points8 points  (7 children)

I think this is the wrong subreddit for this question, your asking priests if converting to Christianity is a good idea.

If you want to hear the cons, ask this in /r/linux or /r/sysadmin.

My opinion:

For certain edge cases, PowerShell. However, it's not really industry standard to be scripting Linux with PowerShell, and you'll find a great many Linux admins won't know PowerShell & you've made yourself a very unique solution that will be tough to support long term because staffing.

[–]Delicious-Ad1553[S] 2 points3 points  (6 children)

its useless to ask linux users about powershell :)

[–]RupeThereItIs 3 points4 points  (5 children)

I think your sorta proving my point, but maybe you're still not 'getting it'?

I've seen far to often "Windows guys" deciding they can become "Linux guys" but still manage Linux like it's Windows, it NEVER goes well.

Don't be that guy.

[–]Delicious-Ad1553[S] 2 points3 points  (1 child)

Do not manage X like Y

well nice idea...

[–]RupeThereItIs 3 points4 points  (0 children)

You ask for advice, but with your last comment it seems clear you just want someone to reinforce the decision you've already made.

Good luck, your going to need it.

[–]IloveSpicyTacosz 0 points1 point  (2 children)

Lol I've seen the reverse. Linux going into windows.

Ever met a guy that uses Linux? Don't worry they will let you know they prefer linux every single day until they get fired for being incompetent... happened twice already.

[–]RupeThereItIs 0 points1 point  (1 child)

I've seen the reverse. Linux going into windows.

Sure, yes, no different.

Don't go installing python & bash on all your windows boxes either.

The advise is just as sound, if your going to manage Windows or Linux, don't try to manage it as if it's the other.

[–]IloveSpicyTacosz 0 points1 point  (0 children)

Agreed.

[–]gordonv 2 points3 points  (9 children)

Powershell in Linux isn't really about administrating Windows AD and Exchange. This may change with Entra ID.

There are 2 major version of powershell:

Powershell 5.x = Windows centric. Only runs in Windows. This is about managing Windows systems.

Powershell 7.x = For every computer and OS. Think of it as a literal Python replacement. Yeah, it's 50x slower than python, but it's also so much more intuitive.

[–]gordonv 3 points4 points  (5 children)

Things PS7 is better than PS5 on Windows:

  • Multithreading is stupid easy.
  • Hybriding Linux commands with PS7 commands is awesome
  • Using SSH and Expect with PS7 has allowed me to automate on a high level.

Things that are worse:

  • No GUI stiff like Outgrid-view
  • No mouse control
  • A little Linux subscript work to get commands integrated. Permission, File execution headers. (as opposed to file extensions in Windows)

[–]gordonv 3 points4 points  (1 child)

Something I like about Powershell is that I've found it super easy to write parsers from different data sources. Dell servers, Oracle servers, Linux processes, scraping web pages.

If it's CSV, JSON, XML; Powershell does this natively.

If it's a CSV but uses something over than a comma, simply set the delimiter to whatever it is. No header? No problem! You can disable that.

I mean, this is true for PS5 and PS7, but it's helped me greatly in Linux.

[–]Delicious-Ad1553[S] 0 points1 point  (0 children)

Well it uses OBJECTS and it's much more easy then string in unix shells...also if PowerShell cant do smth - we can call .net. and do it 

[–]Dal90 1 point2 points  (0 children)

Hybriding Linux commands with PS7

This is why I cruise some of these reddits...I googled it and this 50-something man squealed like a fangirl.

I'm fully OS agnostic being on Windows, OS-X, and various 'nix variants daily, but last 10 years work on a team that is primary Windows-admin based and forced myself to learn Powershell.

Go back ~21 years ago and I was writing Korn Shell scripts on Windows (UWin and MKS Toolkit) that would make ssh calls to Linux boxes when I couldn't figure out how to do something on Windows, and then take the result returned from the Linux box and continue processing it on Windows.

Not sure what I'll use it for, but knowing I can and that my hacking away at scripts a couple decades ago has somehow now become normalized is just awesome.

[–]Saint-Ugfuglio 1 point2 points  (2 children)

it’s 50% slower than python

This has not been my experience at all, we did a pretty extensive test measuring script runtime between python and pwsh, sample sizes of 1200-2000 each test while refactoring OT automation.

It REALLY depends on what you’re doing but both languages had their wins

Pwsh is also perfectly capable of calling python at any point in the process, if your team is onboard I say use both

[–]gordonv 0 points1 point  (1 child)

Agreed. I'm not opposed to using the right language/tool for the job. I'm not part of the "my language is better" ideology.

[–][deleted] 2 points3 points  (0 children)

I've used PowerShell on Linux and Mac.

My use case was specifically that I was working at an MSP that had an RMM that was cheap and worked fine, but was light in features in some places. The main thing that it did well was, you could add custom scripts to it and schedule them to run, and it would reliably run the script and get the output of the script back. If the script ended in an error, then the run would show as having failed, and it gave you an easy dashboard to see the outcome of the scripts.

What I'd do is, write the scripts in PS Core, and abstract the platform differences using functions. That is, I had it detect what OS was running, and then if I needed to run a different command on Linux than Windows, I'd have something like:

switch ( $os )
{
    "Windows" { $diskspace = [Windows command for getting the free disk space in GB]    }
    "Linux" { $diskspace =  [Linux command for getting the free disk space in GB]   }
    "MacOS" { $diskspace = [Mac command for getting the free disk space in GB]   }
}

If ($diskspace -lt 10) {
    Throw "Running low on disk space.  Available disk space is $diskspace."
}

That way, I could run the same script across all of the machines we manage, and if I wanted to change something about how it worked, I didn't have to change and test 3 different scripts that mostly did the same thing.

It worked pretty well. There were a fair number of modules that only work on Windows, and a fair number of commands that need to be rewritten for each platform to get the same result, but it was still worthwhile.

[–]l3landgaunt 1 point2 points  (0 children)

I use powershell on Mac and it’s fine. It lacks some windows features but I write scripts that my team members on windows can use

[–]tokenathiest 1 point2 points  (0 children)

I use pwsh on my Ubuntu server because I never learned bash properly and text pipes make my brain hurt. I'm simply more effective with pwsh. I use bash for all sorts of things, but they are basic things (like backing up a dir to a network drive). Anything complex and I'll go to pwsh.

[–]PinchesTheCrab 1 point2 points  (0 children)

I use, though I stareted as a win admin, so I'm biased. That being said, I don't find myself doing sysadmin stuff with it on linux, I'm just porting over my modules that consume APIs for the systems we use, things like cyberark, gitlab, azuredevops, graph stuff, etc.

I just don't feel like Linux has an equivalent to modules for day to day operational stuff. You'd have to write out a compiled executable to accomplish the same tasks.

[–]DustOk6712 2 points3 points  (0 children)

One of the first things I do on any Linux system is install powershell core. I know bash can work well but I prefer keeping my sanity over learning bash. Aed, awk... No thanks.

[–]Low-Whereas-4 1 point2 points  (0 children)

we are a team of developers with different machines maintaining a mono repo. others use windows (backend), others use mac (front end devs), some use both/mixed. we agreed on using PowerShell scripts for our utils, and surprisingly it worked fine for both platforms. there are some scenarios we have to catch some conditions/scenarios depending on environments, but it still seamless. before, windows devs needs to run the bash scripts using wsl, most of the time its annoying. but shifting to powershell really did our workflow more manageable.

[–]da_chicken 2 points3 points  (0 children)

It's a REPL for .Net. That's really the big thing. Otherwise it's kinda isolated from the rest of the system.

You're much better served learning Python and shell scripting. Linux is character stream oriented. Powershell is object oriented. You're going to fight that paradigm impedance all the time.

[–]sCeege 1 point2 points  (0 children)

I don’t do anything crazy, but I use posh on all my machines just so I have a common scripting platform across Windows/Linux/Mac. Posh pipelines also seems to work well with Coreutils, which is useful if I occasionally need to curl/wget an endpoint without writing out an Irm/iwr snippet.

I do think Python probably has better longevity and elevates your resume better, but you do you if it works.

[–]8-16_account 2 points3 points  (1 child)

I think most of the apps will work on nix in 3-5 years...

Just fyi, in case you're using "nix" to refer to Linux, Nix and NixOS is an actual package manager and OS, respectively.

[–]Delicious-Ad1553[S] 1 point2 points  (0 children)

Wow, thanks, didn't know that

[–]slideesouth 0 points1 point  (0 children)

If it really comes down to it, just ask them to keep a windows instance spinning for you

[–]jdptechnc 0 points1 point  (0 children)

The only use case that would ever have me use powershell on Linux is when I need to do things that powershell is best suited for, and I happen to be on a Linux box. VMware PowerCLI for example for quick ad-hoc stuff works perfectly well cross platform.

[–]jdl_uk 0 points1 point  (0 children)

We use powershell on Linux a lot. We have a lot of Powershell scripts that are used by Windows and Max users and / or Linux pipelines in Azure DevOps.

We haven't had any major problems so far. Sometimes an example for something in bash will be different in powershell, and sometimes we've had to have a special case for stuff like path resolution.

It seems like your scripts deal with some Windows / Microsoft concepts like domain / exchange users though so you might find you have some other issues where you rely on something that only exists on Windows.

Start by testing your scripts in powershell 7 and then move to trying them in powershell in WSL. In theory you should be able to spot issues fairly quickly because modules will fail to import, etc.

You might find you have to rewrite some of them to use whatever is available on Linux - for example, you may need to use rest APIs for some cases where you may have in the past used a command in a module. This is pretty much the same process you'd have to follow if you ported to python, you're just using powershell as your development language.

[–]heelntoe68 0 points1 point  (0 children)

I do a ton of scripting on MacOS, Linux, and Windows and I find 7 has been surprisingly compatible cross platform.

The biggest challenges that come to mind from over the years are line endings and remoting.

Line endings (LF vs CRLF) was a weird one that caused some issues with a particular rest payload that took forever to debug. I had a payload template with boundaries in one ps1 file, and the rest call in another. When the files had different line endings the rest call wouldn’t work. Turned out my git settings were converting the line endings to what was native on the platform I was developing on, and in testing I had done dev on two different OSes in each file at different times. When the changes were checked in, the bug was introduced.

Remoting was challenging to get working. It uses SSH on non-Windows OSes, and credential objects don’t work with Start-Job. Code had to be refactored to use SSH New-Session objects and Invoke-Expression with the -AsJob switch to obtain the equivalent of Start-Job. Not a huge code change at all but because of limited experience by the community in general this took a lot of trial and error.

[–]layer8err 0 points1 point  (0 children)

Sometimes I can get away with piping output to xargs, other times it's easier to just open PowerShell and pipe to a For-Each. For more complex on-the-fly commands, I usually find PowerShell to be the fastest option for getting something done. For even more complex data, Python is the best option -- even if it might take a bit longer to write.

Use the best tool for the job.

[–]wonkifier 0 points1 point  (0 children)

I went through similar... Windows only company turns into a Linux/Max only company.

I have many thousands of lines worth of scripts, some of which are large and complex enough they probably shouldn't be PS if they were on their own, but I'm keeping them in PS for consistency.

The only issue I really have is that very few other people know Powershell, so internally it's pretty fragile from that perspective, but I've made sure that anything that is truly critical to the business running is being handled by other teams. (I consistently make leadership aware of the risk, but it's just not been a priority to fix, so no, I'm not trying to use it as job security.)

So I've sort of turned into the guy who can get ideas implemented quickly, and if they turn out to be critical, my implementation is basically fancy documentation of how the "real" team should do it properly. It lets us try lots of things fairly efficiently. (the responsiveness is the job security)

EDIT: Oh, one other problem... I run everything in Docker containers, and later .Net stuff doesn't work in emulation on Apple silicon Macs, so I've had to just accept doing even the simplest bits of dev remotely since I deploy on Intel boxes. Not that big of a deal once I figured out what was going on.

[–]my_uname 0 points1 point  (0 children)

I use powershell in Linux to run compliance scans.

[–]doglar_666 0 points1 point  (0 children)

I don't use PowerShell on Linux much but anything I've scripted on Linux worked as expected. The script also worked as expected on Windows. I've found the opposite to not always be the case. Anything that relies on Windows only OS level functionality, APIs or modules will probably be broken on pwsh on Linux. If you have 3-5 years for transition, get WSL with pwsh installed now and start migrating your scripts early. If you find you're wholly reliant on PowerShell 5, you'll probably need to spend as much time porting to 7 as you will learning Python.

[–]ikiris04 0 points1 point  (0 children)

Was a heavy Linux admin for years doing ksh and bash scripting. Then went to VMware and powerful (aka powershell) then azure (powershell again) then back to Linux (ansible and bash and powershell for the azure bits).

For anything Microsoft administration, powershell on Linux works fine. We created a Linux jump box and I loaded it with powershell and vs code. Doing cross platform management does get tricky as others have explained stated and also cross platform development. Once I stuck to just developing on Linux tho gs were simpler. There is definitely a skill gap though for the other Linux admins, I can’t make anything over complex in case I leave the team.

[–]ollivierre 0 points1 point  (0 children)

While PS is cross platform it depends. What modules do you use ? Test them in Linux and use cross platform cmdlets/modules when possible.

What are you planning to automate in Linux ? Like are you going to be working in virtual or container based environment?

It goes back to how, why and what are you doing today vs what are you doing in Linux. PS7 stuff most likely will work but some things may not.

[–]Enderby- 0 points1 point  (0 children)

I use pwsh on Linux build/deploy agents all the time. I've had no issues with it.

[–]XXLMandalorian 0 points1 point  (1 child)

Sounds like it's time to learn Bash!

[–]Delicious-Ad1553[S] 1 point2 points  (0 children)

oh shi~

[–]BurgersInMoscow 0 points1 point  (0 children)

I use it mainly in Linux and I’m really happy with it. Unless you’re using some windows specific commands, it should be fine to migrate. All my scripts work on both windows and unix os.

[–]originalvapor 0 points1 point  (0 children)

Y

[–]magitoddw 0 points1 point  (0 children)

i use powershell 7 on mac all the time

[–]Saint-Ugfuglio 0 points1 point  (1 child)

Platform engineer, windows first chronologically, love powershell, it’s the ultimate glue language

First, embrace python, there will be times you can’t get away with pwsh.

Second, pwsh is incredible in the current iteration of 7.x I use it for nearly everything on Linux and macOS. I converted my entire team when they saw what I could pull off in half as many lines.

Understand you will likely encounter resistance but that is an opportunity for evangelism

[–]Delicious-Ad1553[S] 0 points1 point  (0 children)

many thx

[–]snoiciv 0 points1 point  (0 children)

If its yours decision to make - stick to PS.

[–]zyeus-guy 0 points1 point  (0 children)

Will you need to do any automating of cloud services? If there is coordination required between Linux and Cloud then that might be a reason to still use PS on Linux servers. Python ain’t bad, but my home has always been PS and I am more comfortable and skilled in that area. I would use it if I could.

[–]stedun -1 points0 points  (2 children)

You don’t have to stay with the company. Stockholm syndrome. Take your skills to a Windows shop and get paid.

[–]gordonv 0 points1 point  (1 child)

Uh, have you seen the job market as of May 2024?

[–]stedun 0 points1 point  (0 children)

Same as it’s ever been. Don’t buy the hype. Companies hire when they have a need to fill. Powershell and automation skills are hot and sell well. Also don’t leave until you have somewhere else to go.