PowerShell goes multiplatform!

iljitsch

Ars Tribunus Angusticlavius
9,637
Subscriptor++
Wait what...? I can now use the Windows Powershell on Linux and Mac?

Any sense in doing that?

Earlier today I found out that Python3 will actually work quite decently on Windows, having the tools to abstract away the difference between Windows and the rest of the world without too much trouble. And although the install is not very noob-friendly, it's not particularly difficult.

So what makes sense here? PS all the way, or have the Windows people install Python?
 

wxfisch

Ars Scholae Palatinae
1,173
Subscriptor++
This isn't really new, PowerShell 7 has been around for a hot minute now (I think 5+ years) but great that you stumbled on it! (of note, this is technically different than Windows PowerShell which is still 5.x; Windows users also need to seperatly install PowerShell 7 to get the full cross-platform experiance).

In terms of what to use, it depends on what you want to accomplish, what you are comfortable with, and what your environment supports.

As an example, if you use Ansible extensivly then just install Python on your Windows machines and be done with it. If you have a lot of PowerShell scripts or experiance then running PoSH 7 may be the move to start maintaining and working with your Linux machines.

For my money though, let the Windows folks use PowerShell and the Linux folks use bash/Python/PowerShell/Tool they are comfortable with unless you truly need standardization of some sort in your environment. Where I am my team uses Ansible on all of our Linux machines but getting Python approved and isntalled on our Windows servers is enough of a pain that we use PowerShell scripts to run tasks against those. Sure it is "double the work", but our workloads dont run in mixed environments (they are all different application servers for distinct enterprise applications) so we would need to develop different playbooks for the Windows stuff anyways.
 

fitten

Ars Legatus Legionis
55,631
Subscriptor++
I've only dabbled lightly in Powershell although there have been a number of scripts that people I've worked with wrote for various reasons that I've used. These days, I'm much more likely to write any scripts in Python since at work, Python is an integral part of our build system so we have it installed on all machines, even Windows machines so for me, Python is literally everywhere.
 

iljitsch

Ars Tribunus Angusticlavius
9,637
Subscriptor++
For my money though, let the Windows folks use PowerShell and the Linux folks use bash/Python/PowerShell/Tool they are comfortable with unless you truly need standardization of some sort in your environment.
Well, I wrote an ebook and used a bunch of lab examples that run Docker containers which are orchestrated through a bunch of scripts: bgpminilab

On Mac and Linux, this uses Bash scripts as these are natively available (although highly outdated on the Mac) and for Windows I replicated those in Powershell. For sure I'm not doing that again.

For a new project I extended the functionality significantly but moved to Python on Mac/Linux, and I was surprised to see how well that works on Windows if you take care of your / vs \ and /dev/nulls. (If anyone cares. Please don't disparage my Python skills, I know they are severely lacking.)

So it's either make things easy on the Mac/Linux people and make the Windows people jump through hoops installing Python, or the opposite by requiring Mac/Linux users to install PowerShell Core. But I think there's also some minor hoops there for Windows people anyway.
 

Technarch

Ars Legatus Legionis
17,068
Subscriptor
Ewwwww why would anyone want that

You know, Powershell can be really powerful. (Too powerful, if I put my security hat on.) But it's such a pain in the ass to write and read. Maybe it's the Bash bigot in me but I just never liked doing anything in Powershell regardless of the underlying platform. Git Bash works pretty well on Windows.
 

iljitsch

Ars Tribunus Angusticlavius
9,637
Subscriptor++
You know, Powershell can be really powerful. (Too powerful, if I put my security hat on.) But it's such a pain in the ass to write and read. Maybe it's the Bash bigot in me but I just never liked doing anything in Powershell regardless of the underlying platform. Git Bash works pretty well on Windows.
Yeah but I don't like bash either. It's useful because you can pretty much depend on it being there although be stuck with a decade old version on MacOS diminishes that.

I find the syntax supremely confusing so whenever I do something that involves logic I just need to copy from examples on the web. So in that sense Powershell and bash are about the same for me. I've been struggling to some degree with Python recently as I needed to do more complex stuff, but there for the most part when I've figured something out it makes sense and it becomes routine.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
SORRY WRONG PLACE

If ya got install something somewhere use a real language and do it in Swift.
It makes use of JIT and has a good standard library for cross platform use in the shell.
Cross platform UniCode string handling and uses URL's for file access.
<https://www.swift.org/get-started/command-line-tools/>
??? Swift is not JITTED it is an AOT compiled language (outside of things like Playgrounds)
 

waqar

Ars Praefectus
4,575
Subscriptor
I have used powershell (powerCLI module) with terraform on a windows 11 build out. For some reason the terraform provider was not doing the static IP address bit.
So I just created a powershell script to change it on the VM, injected it into VM with powerCLI running on my control node (ubuntu) then used powercli to execute it on the VM.
worked well. But its not a complex use, to be fair.
Felt just like does on windows, I'd say better, in fact, the auto-suggest as you typed in commands was attentive. Windows is positively slovenly in comparison.