Earlier this year, I needed to learn PowerShell scripting for one Windows-related project, and I have tried it out a few more times on Mac. It has quickly become one of my favorite tools for automation and scripting—taking on jobs that I would have otherwise tried to do with Node.js, Shortcuts, macOS Automator, or heaven forbid, Bash scripts.
I get it now. PowerShell is great, even if you don’t use it as your shell, and even if you’re on Mac or Linux.
↫ Corbin Davenport
I don’t use the shell often enough on any of my main machines to have much of an idea about the strenghths and weaknesses of PowerShell compared to more traditional shells, but this is definitely not the first time I’ve heard a lot of praise for it from people otherwise knee-deep in the UNIX and traditional shell world.
There really must be something to this, and since PowerShell is also available on Linux and macOS, it’s pretty straightforward to give it a go without having to deal with Windows.

PowerShell kinda sucks as a shell, fish is much better, but it’s pretty good at programming tasks. It has a bit of learning curve and requires a lot of looking up how to do things, but it’s definitely powerful and nice to use on Linux too.
I agree, PowerShell is not a great environment, but it really impressive for scripting. One of my last projects before I retired was rewriting several C programs to PowerShell because a vendor had dropped C API support for accessing their database. It took some time to get used to the PowerShell way of doing things, but in the end they were very clean. The biggest drawback was speed; since PowerShell is interpreted, some of the scripts that retrieved large collections of data were slower, but not unreasonable.
That was my experience as well. As long as I’m not speed-limited by PowerShell itself doing data processing it’s great. Once I am, Python mops the floor with it, let alone faster languages.
From what I’ve seen of the syntax, it looks a little too Win32API+VisualBasic-y for me.
…and syntax is one reason I wasn’t too keen on learning Ruby+Rails when I already knew Python.
These days, if I’m not using Rust for the amount of compile-time confidence and easy deployment it gives me, it’s probably either because there’s still some Python library that hasn’t gotten a suitable Rust replacement yet (eg. PyQt, Django’s ecosystem) or because it’s so quick and dirty that I couldn’t talk myself into an on-disk representation beyond “one file with embedded configuration that I edit as I go”… in which case I also use Python since rust-script is still a bit rough.
ssokolow (Hey, OSNews, U2F/WebAuthn is broken on Firefox!),
I’m on the same page. Powershell is a lot better for shell scripting than batch files, so it’s a very welcome addition for windows scripting. I like it better then bash too, bash is quite bad at all but the simplest tasks.
I’ve used powershell to download data sets and create formatted excel spreadsheets, but this was probably pushing my comfort using powershell. Despite it’s ability to do complex things, it falls short programming complex software. Python users aren’t likely to see any reason to use powershell.
More of us need to do that 🙂
Is anyone else effected by the serious PHP vulnerabilities reported this week? By sending enormous payloads, attackers can trigger PHP memory overflow logic, however faulty logic results in a use after free fault, potentially enabling remote execution and privilege escalation. The fault(s) can be triggered via PHP’s input parameter parsing code and the vast majority of PHP websites are vulnerable even when the PHP code is correct.
Apparently this fault was present in PHP for decades.
This wouldn’t have happened in a memory-safe language. This is why memory safe languages like rust are so import.
I know you appreciate this, but most developers don’t.
Humans can’t be trusted to write 100% fault-free code in C at scale, no matter what they say!
@Alfman,
No, just you! 😀
I never felt so good when doing “Java only”. God is with the dumb, as we say in German.
Andreas Reichel,
Haha. The thing is most of the web is on PHP and the exploits are in the wild now.
https://aws.amazon.com/blogs/security/amazon-threat-intelligence-identifies-php2shell-exploitation-prior-to-public-disclosure-in-madpot/
Osnews uses kinsta for managed wordpress hosting, and they’re still running PHP/8.3.35. The patched version for that branch is 8.3.36. I suspect millions of websites will remain vulnerable for some time.
My biggest concern was about our Routers and Security Cam’s and their management UIs. And I have all kind of Temu crap here around (thank you, my beloved wives).
But again, the Emperor protects: One by one I ran port scanners and Curl scripts to understand what tech stack those devices were using and it all seems to be ASP/CGI only. That’s probably the first time every that I am grateful for the MS/Windows exposure of SE-Asia.
So, still: only you! 😀 God bless America 😀
If it’s managed hosting, I’d be surprised if they didn’t deploy early countermeasures through their WAF before risking all their client’s websites via a PHP upgrade. This is how one of the hosting providers used at work did it. And they didn’t even upgrade the PHP version yet, just recompiled the already deployed one with the patch.
I have some PHP stuff I’d like to rewrite at some point (eg. a WordPress blog I’ve been babysitting since 2005 where I want to switch as much as possible to static generation but I’m not willing to take a hit on functionality or 404 URLs, so it’s taking time to track down or write things like https://pagefind.app/), but it’s on shared hosting where my provider handles PHP updates.
When I don’t need the full power of Django’s ecosystem, I tend to do stuff like https://github.com/ssokolow/fan_remote/ which also serves as a public demonstrator for my standards for designing systemd unit files for an extra layer of defence.
I like Rust on that front because, if I’m not requiring some kind of external thing (eg. the Python-based driver for the USB X10 bridge in that project), it’s pretty easy to use the musl-libc target to make a single-binary static build and then crank down the restrictions to the point where it basically can’t see the real filesystem at all.
ssokolow (Hey, OSNews, U2F/WebAuthn is broken on Firefox!),
If your reason for wanting static files is performance, a well optimized PHP website is actually quite fast if used conservatively.. Computers are so blazing fast today but we tend to forget that because modern bloat keeps throwing more and more busywork at the CPU and IO subsystems that they seem slow. The inefficiency of modern is the reason dynamic PHP gets a reputation for being slow. WordPress has to dispatch SQL queries per entity, which results in more IPC, index evaluations, disk traffic, etc. But If you architect web pages without these bottlenecks: dozens of queries, file IO, joins, records, etc…then PHP will probably saturate the bandwidth available.
Even for simple websites I personally wouldn’t use static files, IMHO it’s better to insert templates on the fly. A well optimized dynamic PHP page that has the template ready to go and holds the content in a compact form might actually use less IO and cache than thousands of static files would.
Your post was more about security though, in which case yeah it’s hard to beat the attack surface of static files. That said, I’d still want some kind of dynamic programming language. PHP might not be the best choice, I’m sure there are safer languages out there, but most of my web work has been with PHP.
Yea, there’s a lot that can be done…but hard to know when it’s worth it.
It’s a blog. The only things I need dynamic code running on a server for are accepting comments and tracking which posts are popular to feed a sidebar widget.
…and given that I moderate all my comments anyway and want my comments baked into the page data so I can include them in a git repo people can clone to mirror it, I may just add a new branch to the mailsend.cgi I use for my contact form.
I am sorry, but I never disagreed with you so much! (And I am actually surprised you are taking this stand.)
Especially when short of resources (like a SME company website), you want to eliminate any and every possibility — and so you run STATIC, plain text websites only. Everything else slips through, just a matter of time. Python Sphinx it is for me. Never regretted it.
I don’t want to be this guy really (because I don’t kick when a man is on the ground), but PHP/WordPress (or any other CMS) looked always “weird” to me. I did not understand it, I did not like it, I was not able to control it — so never used it.
ssokolow (Hey, OSNews, U2F/WebAuthn is broken on Firefox!),
I’ve visited your blog, I’m not sure if my point was clear though. I wasn’t suggesting to use PHP to create “dynamic content” in the typical sense, but to use a very basic PHP script to assemble your static parts into a page. Ie header + contents + footer.
This way:
1) only one copy of the header & footer need to be stored instead of thousands
2) changes can be made in one place and they immediately take affect site-wide without needing to push out batch updates on thousands of files.
3) this model performs extremely well.
4) you don’t end up locking yourself into a less versatile architecture.
I used to deal with static HTML websites, and TBH it was so cumbersome I never want to do that again. Even using deployment scripts couldn’t solve everything I wanted to do….I did a job where I had to work with thousands of static pages that had been updated by hand so I couldn’t even reliably create automation tools to work with them. It was a total nightmare. All the pages ostensibly used a single site template, but as they got copied and changed over the years more differences arose and maintaining them was a disaster. Using PHP or another language at a high level to manage contents as organized units solves most of these admin issues.
Now you can “solve” it by creating a “header.html” and “footer.html” then iterating over a “contents/*” directory to produce your final static files. I suspect this is what you had in mind, right? I just don’t think you’re going to see much of an advantage going that route, everything can be done better with PHP while still being much faster than your current wordpress website.
It might be interesting to see benchmarks comparing the different methods. Let me know if you ever do update your website or if you need help exporting data from wordpress. It’d be ironic because most of my work goes in the other direction…importing data into wordpress, haha.
@Alfman:
What is cumbersome about a Site generator (e.g. Sphinx, Hugo, Bakery — whatever tickles your fancy) and RSync/RClone? To me this feels like the most intuitive way before I even would invest time learning PHP or WordPress.
@Alfman:
[q]All the pages ostensibly used a single site template, but as they got copied and changed over the years more differences arose and maintaining them was a disaster. {/q]
That’s what you have template languages like Jinja for? I really don’t get you on this one (but I am curious because your view usually hold lots of merit).
Andreas Reichel,
You shouldn’t be too surprised, considering my background. I would say that basic website dev is be pretty straitforward. Ironically many modern frameworks make things much harder to do rather than easier, haha.
What you need to understand is that the market shoved most web dev work to wordpress, myself included. It took over and the demand for custom websites cratered. I’d rather be doing that but it’s not what it used to be.. At least wordpress is better than magento, which is so inefficient that even a basic website needs a monster server to not feel sluggish.
They fundamentally can never reach feature parity with PHP. There are so many examples, but lets say you want a search page or comments….PHP can do those, HTML files can’t.
Alfman,
I’m likely to host on GitHub Pages to reduce the bus factor, I’ve run the same WordPress theme (and desktop background) for something like a decade, and I’ve written my own static site generators in Python for more specialized applications in the past. (eg. http://vffa.ficfan.org/ is on a private static site generator that performs Python-based CSS and HTML validation and does internal broken-link checking)
Also, pushing the source files to GitHub in one branch and the rendered ones in another means I can do what I’ve always wanted and allow people to grab a .zip mirror for offline reading with a couple of clicks.
I also have the beginnings of a static site generator in Rust that started as a quick frontend around pulldown-cmark for generating single-page documents crossed with a WASIp2 plugin host practice project and since it’s started to grow into my dream Markdown renderer, I’ll likely build (or borrow) a multi-file architecture around it and use that. (eg, It’s already got sandboxed plugins for things like loading a separate CSV/TSV/etc. file and rendering it as an embedded table, rendering Graphviz DOT or SVGBob from codeblocks with special language names, latex2mathml rendering to power the Markdown equations syntax extension, and various other things.)
…though I’m likely to switch to Comrak since it seems it’ll be much easier to reconcile my big collection of keyboard key/gamepad button “image” (CSS) shortcodes with Markdown definition list markup if I use a parser that actually supports shortcodes so they’re not fighting over the meaning of colons in edge cases.
Allowing people to download an archive of rendered pages efficiently is a design goal. Pre-rendered HTML in GitHub Pages or an equivalent on a competing service is a convenient way to do that.
I’ll make a note.
Previously, the big hold-up was that I was feeling too burned out to set up a LAN mirror of my blog so I could run a page spider over it to generate a list of all the URLs that need to be kept functional in the changeover. These days, when I’m not feeling so busy and/or burned out, I’ll just use Docker for that.
That’s literally what the https://pagefind.app/ component I linked is for. It’s basically a separated, designed-to-be-embedded competitor to the client-side/JavaScript fulltext search offered by things like Sphinx and rustdoc, optimized with a chunked index to minimize how much each client has to download to perform a search.
As for comments, a lot of people use Disqus for that or self-host an open-source equivalent like Commento or HashOver.
ssokolow (Hey, OSNews, U2F/WebAuthn is broken on Firefox!),
Sorry, what does this mean?
Sounds like you’ve got a plan 🙂
You probably won’t want to hear this, but I think everything you are building to render HTML files with rust ahead of time would probably have just as much merit generating the same content directly in response to web requests.
I am biased, but to me that’s just a worse implementation of a feature that is easier to do with a dynamic website. Even if I wanted client side search, I would still prefer working with a proper database than static HTML files because databases are so much more powerful. Once you are proficient with a database you never want to go back. I concede there’s a learning curve that may be difficult to overcome.
This week I implemented a real time search for a customer who gets frequent database updates (every hour or so). So sure I can’t deny that it could technically all be done with static HTML files, but I honestly don’t think we get much for the effort it would take to avoid PHP. Regardless of the framework you use, you still have to be able to render pages whether they get saved as HTML files or sent to a web browser. So I think the HTML output generation complexity is pretty similar. Either way we generate the same HTML, it’s just time shifted. However with HTML files you have some additional work to generate/transfer HTML files. Moreover you’d have to generate the full catalog of HTML pages when the source data is updated in case those pages might be requested. With PHP you only ever need to generate pages that are actually being requested. You can even use a full page cache so that PHP only generates contents once (though again I want to stress that PHP overhead is negligible for simple templates).
Outsourcing dynamic features is certainly is an option. Although personally I’m not a fan of somebody else controlling “my” data, tracking me & my users, etc. Not having database access is a con. Many of these offloaded services get cross site scripting access back into the website. They may not be malicious, but it doesn’t sit right for them to have script access on the website. So my advice is to not go this route given the choice.
I definitely prefer self hosting when possible, however to be fair there are pros and cons. I understand that someone might not have the facilities to set up their own dynamic services and naturally outsourcing is the goto answer for them. Another barrier is that it takes skills and patience to set up websites and services yourself. That said, if you have the skills to deploy these page generators yourself, you probably have the skills to deploy a dynamic website. Most hosting providers make this pretty easy out of the box and the bar to entry is pretty low. I concede that they will push wordpress hard, which is way more than most people actually need. Oh well.
Alfman,
If I get hit by a bus, I want to minimize how much I have to rely on my family to keep the site up.
As a retro-hobbyist, I’m well aware of how difficult it can be to track down programming resources from the 90s.
It’s predominantly repurposed stuff for other goals where I’m deduplicating projects by doing this, and it’s informed by prior experience with which solutions last how long without needing manual upkeep.
I’m proficient with databases… heck, I’m currently writing something to index images on my PC. I just think it’s overkill for full-text searching a blog… especially when I’m rewriting the generation in Rust anyway because, over the last 20 years, PHP went from the cool thing I write everything web in to that language I really don’t like working in for lack of compile-time checks.
(When I get around to doing some parsing in Rust, I’m planning to use LR parsing instead of combinators or PEGs because it’s the approach with the most ability to catch errors in the grammar definition at build time.)
Doing static site generation and using Rust with musl-libc static linking for what I can’t static-generate are both measures for minimizing my projects’ abilities to throw new work at me on a schedule I don’t decide. Also, I have projects where I need static generation either way.
(eg. the single-file side of it partly exists for creating “applications” which push the bounds of what you can “install” on an iPhone without giving Apple personal information despite the Files app disabling JavaScript for displayed HTML files so I can carry around an offline “used bookstore wishlist” pseudo-app.)
(And this is all part of a bigger push to deduplicate as much of my stuff as possible. PHP and Go are kind of noteworthy shortfalls in the ability to write it once in Rust and then efficiently maintain comfy bindings.)
But it avoids having to maintain backups because, if the server goes kaput, I just change the push URL and re-run the same rsync wrapper I use to push the site live in the first place… plus, GitHub, Cloudflare, and a bunch of other places give away static content hosting suitable for a blog for free and I think Cloudflare will even do DNS nameservers for free.
To some extent, this project is also about cutting down my ongoing expenses.
ssokolow (Hey, OSNews, U2F/WebAuthn is broken on Firefox!),
Responding here b/c wordpress comments are chaos!
Ah I see. I might have gotten it if you said “cancer factor”.
People have different needs, but I do find databases to be valuable even for small projects.
I’m in total agreement about PHP. It was written by amateurs and it shows. It’s taken lots and lots of code-breaking changes to improve the language, and to their credit it has improved a lot. It still has quirks though and as a scripting languages it’s not very proactive about compile time checks.
Oh I see, your goal is to use static pages because you can load them in a restrictive environment like IOS. Makes sense.
I’d say the same is true of PHP. You can incorporate external dependencies, but it’s not uncommon for PHP websites to follow the old school “just unzip a bunch of files” deployment method. Although I wouldn’t know where to host it for free.
Yeah. Everything has been lurking up in price.
https://en.wikipedia.org/wiki/Bus_factor is an established item of jargon.
@Thom
I would like to question if this makes much sense because:
1) there are better shells installed per default on Linux and MacOs
2) there are better scripting environments installed per default on Linux (there are not many Distributions around w/o Python or Perl).
So why exactly would anyone take the hassle of installing PowerShell (unless forced to write Powershell scripts at gun point).
well, I have to manage some Azure resources, and a whole Microsoft Entra setup. To get to the point where I can manage the system and track changes, I had to work with a combination of Terraform/OpenTofu for most of the baseline, and Powershell for all the MGraph magic not yet supported by any Terraform provider. All of that encapsulated in Justfile recipe. It works well, Powershell does the job to talk to Microsoft without too many issues (except that’s still Microsoft APIs…)
I like the object oriented nature of the language, the mandatory verbs in the functions naming, the pipes !! But I’m not a fan of the case unsensitiveness, the fact that you can do the same loop in, like, five different syntaxes, the shell itself is mediocre.
Powershell is scripting is mush better than bat scripting. But I’m not using it, because in closed enterpise environments the administrators can limit the PS script execution. So in the end i’m using a portable python environment for scripting. That doesn’t bother the IT guys,
When powershell first came out, a LOT of lazy sysadmins totally ignored it and continued doing things the old way. Powershell was installed and available, but it was totally ignored.
Malware authors are not so backwards so they learned powershell and put it to use, once malware written in powershell started to hit those same lazy sysadmins panicked and their first thought was to try and remove or prevent use of powershell.
There’s nothing you can do in powershell that can’t also be done with other languages, so preventing the use of powershell doesn’t stop any malicious activity it just forces the attackers to do it another way.
Also trying to block powershell is never entirely effective, there are numerous ways around it and those ways are usually far less visible than using it straight up.
A competent sysadmin would have started learning about powershell when it was in preview, and made heavy use of it once it was rolled into production builds (vista/2008), and today would be using it heavily and monitoring it for abuse rather than trying to block it.
Classic Microsoft “Internet Explorer is too baked into the bones of the system to unbundle. It will sit there until people give in and use it.” design.
I really do prefer the head-start Linux has on MinWin-esque “If an application needs it, it can be present just inside a sandboxed container for that one application” modular architecture.
Not using PowerShell as a MS sysadmin of any stripe is usually a red flag to me that the person is not good at their job. You can hate it all day long, but not using it or not knowing how to use it at this point means you’re incompetent at your job.
I’d have the same response to someone saying they’re a *nix admin but can’t/won’t use shell scripts.
drugajin,
It’s not a matter of incompetency but a matter of taste 🙂
I wouldn’t think less of someone who avoids bash in favor of python, perl, php, etc. More power to them I say! The only thing I like *nix shells for is piping data around, because that’s a core competency for shells. I’d rather not use one if there’s any serious programming involved.
Exactly. I use Python in place of shell scripts because it’s just a more pleasant thing to work in. Here are four examples:
1. Whitespace splitting designed for an interactive shell is just unpleasant to work with when I can instead use shlex.split only when I want it.
2. try/except/finally is just more pleasant to work with than trap.
3. It’s nice to have proper array/list handling designed in from the beginning instead of bodged in later.
4. Python is much more performant when doing things where I can avoid a ton of subprocess invocation. (eg. When I rewrote my script for generating/updating Flatpak launcher wrappers, it was somewhere between 10x and 100x faster when I could use PyGObject to call directly into a persistently loaded .so file instead of firing off multiple subprocess invocations per app. It took it from taking 5-10 seconds with the apps I had installed to less than a second.)
My day job is and has been mostly heavy Microsoft IT shenanigans for a long while. PowerShell is nearly indispensable and is BY FAR the best way to script most things therein. When I run into programs or systems that make me bust out .bat/.cmd files or something else, I wince and know it’s going to be stupid and tedious to deal with.
That being said, I wouldn’t touch it with a 10foot pole otherwise. It’s not great as a shell and outside of Microsoft world, it’s a D student, at best.
PowerShell syntax of -eq -ne etc for comparisons is really really really really annoying.
VBScript was invented in 1996.
Annoying Microsoft should have improved/extended VBScript instead of inventing a whole new language in PowerShell.
Microsoft could have created VBShell 🙂
tom9876543,
-lt blockquote -gt PowerShell syntax of -eq -ne etc for comparisons is really really really really annoying. -lt /blockquote -gt
What were they supposed to do? Add new characters to everybody’s keyboard for logic comparison? That’d be nuts.
-lt blockquote -gt
VBScript was invented in 1996.
Annoying Microsoft should have improved/extended VBScript instead of inventing a whole new language in PowerShell.
Microsoft could have created VBShell
-lt /blockquote -gt
I’ve got some bad news for you…
https://www.elevenforum.com/t/vbscript-deprecation-in-windows-11-timelines-and-next-steps.25396/
There’s still quite a lot of businesses using office VBA macros to implement reporting and business rules for all sorts of stuff. Phase 3 is the next step and once microsoft follows through and breaks VBA, I suspect a lot of business spreadsheet automation will break out in the wild.
Unlike you, I don’t have much love for VBA, however microsoft’s reasons for killing it off are pretty draconian. People may not be aware there’s an agenda behind this. It’s not just about replacing old technology with new languages, they’re actively severing connections with technologies that owners used to be able to run locally. Microsoft’s official replacements are all locked into online subscriptions/cloud accounts..
– Office scripts – runs only on microsoft servers.
– Power automate – cloud based, internet & sign in requirements.
– Python – runs on microsoft servers.
https://support.microsoft.com/en-us/excel/python/introduction-to-python-in-excel
At least there are still COM objects, meaning we can automate excel from the outside. However everything built into office going forward has been engineered to require a microsoft connection. Local execution and control has been systematically engineered out of office. I have huge problems with this enshitified version of the future and lean FOSS whenever practical….however a large proportion of businesses are deep inside microsoft’s walls.
Alfman,
“What were they supposed to do? Add new characters to everybody’s keyboard for logic comparison?”
This may be the stupidest comment in history of Osnews.
Almost every programming language uses = or == as equality operator, not a stupid -eq.
-gt is stupid when virtually every other language uses >
Thank you for posting the official confirmation the VBScript is a dead language. I have learnt PowerShell and haven’t touched VBScript for at least 10 years.
tom9876543,
Thanks 🙂
I was hoping the joke would be clear, but maybe it was too subtle. The blockquote mistakes weren’t an accident, I was pretending that < and > didn’t exist and that HTML used -lt and -gt instead. That cracked me up, oh well…I guess even jokes have a bus factor.
Apologies I did miss your humour. HTML has the special symbols > etc but HTML isn’t used for scripting 🙂
tom9876543,
Likewise, though my missing it was just because I’ve seen far too much broken markup which resembles that due to CMS mangling.
These sort of threads are pointless, an invitation to a flame war.. How to engage when there is sort of BS?
“Python might be the best alternative, but its lack of curly braces makes me sad”
Or
“For anything slightly more complicated, Bash scripting is just the worst. There are almost no “built-in” functions—you are supposed to use POSIX commands for common tasks, like file operations or parsing text”
Supposed to? Says who exactly? He’s also surprised some systems don’t ship with sudo, and that a bash shell script might not run correctly on other shells.
Mr Davenport just needs to mature a bit.