I find PowerShell, the language, verbose and not very ergonomic. This ship has sailed, but I wish Microsoft had done something to make Windows automation a little closer to other platforms, so that it could benefit from the good software that exists on other platforms.
It seems that VBA will continue to exist as the programming front end for MS Office, which is unfortunate. They had announced Python support for Excel a while back and I wish it was better promoted as a viable VBA replacement.
It may have a separate timeline but it does seem to hint at going out the door in similar order on Office as well. I think the Python in Excel stuff is still in beta but things like lambdas, regex or Office Scripts all actually work (even on the web versions) and start taking big bites out of why you'd want to look at VB. New Outlook dropped VB support even on the desktop and I don't think they plan on maintaining separate development platforms for the other apps forever.
Python in Excel could have been amazing, except Microsoft executes it in a cloud environment and require a Cloud Service account to even open spreadsheets with it in.
I'd strongly recommend people avoid Python in Excel, it is a Trojan Horse into forcing you to subscribe to access your own spreadsheets.
It’s ironic that Microsoft was founded to provide software for microcomputers where the whole idea was that you own the CPU and don’t need to pay anyone or ask permission for access.
And now they’re full circle back to mandating the timeshare computing model even though the local CPU has incredible performance.
That's precisely what I mean, rather than maintain desktop and web apps for the Office suite Microsoft is continually moving towards a single stack of web based apps (chat and email being the first two so far). The web based tools dont have VB as a lot of the VB integrations wouldn't be possible on the web anyways.
A deep chill ran down my spine as I remember all of those VBA tools I updated/generated during my first internship... some of those are still being used in some semi-industrial applications.....
IIRC, MS has not updated VBA since 2007, but they can't get rid of it because of the millions or billions of spreadsheets out there that still require it.
They are trying to push excelscript aka typescript aka office scripts but uptake has been very slow.
That's only a slight exaggeration, if it is an exaggeration at all (there are all kinds of splody things that are managed by VBA scripts that some intern wrote back in 1999, or that can only be modified by Bob, who retired back in 2006).
IMO, the problem isn't that you can't use it in a terse way, it's that even though it gives you lots of options for terseness (type, cat, and gc are all aliases for get-content, for example) people naturally try to code in the canonical way and they assume that's the long-form cmdlet names. In Unix, "ls" is what you get so it has to be canonical. In PowerShell you can use ls or dir or get-childitem but there's nothing to hint which is correct to use in a proper script, so when you see example code it looks like "get-childitem | foreach-object {...}" instead of "dir | %{...}"
Scripts should not use the aliases because they can differ across machines or users. The cmdlet names are stable. That being said, for quick one-off scripts my code looks very much like my command-line usage, which is somewhere between terse and golfed.
Idiomatic PowerShell embraces the pipeline, though. The number of scripts I've seen in the wood which were haphazardly ported from VBScript or C# showed, however, that people don't care about idiomatic.
Built-in aliases are guarateed to be present, so you can depend on them. There are other features, like shortened parameter names that might become ambiguous when new parameters are added, that aren't guaranteed backwards compatible, but aliases are stable.
1. UNIX-compatibility aliases like "ls -> Get-ChildItem" and "cat -> Get-Content" are not defined in PowerShell on Linux or macOS. For a complete list of these, see the PowerShell source code[1] (look for "#if !UNIX").
2. A number of aliases from PowerShell ≤ 5.1 were removed in PowerShell Core (≥ 6.0), including the particularly annoying "curl -> Invoke-WebRequest" (conflicts with curl.exe) and "sc -> Set-Content" (conflicts with sc.exe).
In addition to the other comment, PowerShell loads a profile script where a user may freely remove aliases or redefine them as they see fit. It's also a reason why my command line for executing PowerShell scripts includes -noprofile.
> I wish Microsoft had done something to make Windows automation a little closer to other platforms, so that it could benefit from the good software that exists on other platforms.
PowerShell is cross-platform and works und Ljnux and MacOS as well.
And it's extremely good on itself already, because everything are objects, instead of just strings (bash, etc.). And because it's .NET you can seamlessly write anything you like including kernel calls, etc. without ever needing something like a 3rd party package like you would with e.g., Python.
Yeah, it is. S/he’s missing the point. Good luck finding PowerShell pre-installed on any server or workstation. Is there even a non-MS sponsored distribution that includes it by default?
With WSL2, is there any objective reason to write new Powershell scripts in 2024? I am genuinely curious because I barely have used Windows these days and had some brief experience with WSL2.
PowerShell lets you script Windows itself. You can configure network interfaces, set group policy settings, change registry keys, install programs, gather diagnostics, etc. etc. Linux has systemctl, Windows has Start-Service. Linux has kill, Windows has Stop-Process. Linux has ip, Windows has Set-NetworkInterface. WSL2 is just a VM - one with a ton of slick host integrations, but a VM nonetheless. Its power to do anything to Windows itself is very limited. It's also not installed by default.
Disclaimer: work for MS, not on PowerShell or WSL.
In addition to the reasons already stated, WSL2 is a heavy dependency. Compared to PowerShell:
1. Typical WSL2 distros require far more disk space.
2. RAM used by WSL2 may not be immediately freed when your script exits.
3. WSL2 distros don't auto-update, so telling someone to install, e.g., Ubuntu via the Microsoft Store is insufficient to ensure a well-maintained WSL2 instance.
4. WSL2 requires enabling Windows hypervisor support, which can be difficult (KVM) or impossible (non-bare metal EC2 instances) in virtualized Windows instances.
While (1) is probably not a big deal and (2) and (3) have reasonable workarounds, (4), where relevant, tends to be a showstopper.
If you write bash to execute on WSL2, you’re just orchestrating the Linux VM (that runs on Hyper-V and is cleverly integrated into Windows and makes you feel like you have a native bash shell). If you want to automate Windows using bash, you need some runtime that translate all Linux-like calls to the Windows COM interface.
I don’t like the verbosity either, but have come to appreciate it as a cross-platform scripting tool for technical people who aren’t programmers. Again, it’s verbose, but more approachable for these new users than unix scripting languages. Being able to run scripts on macOS and Linux is a bonus. Given all this, I’ve come to peace with PowerShell.
In most normal languages, a non-void function returns either null or some data. Normally, the type of data is always the same. So your function returning a string will never return an int. Either it returns a string or an int. In PowerShell this is not guaranteed for all the functions in packages supported by Microsoft. A function returning a list of strings, can sometimes return a list of something that are not strings. This is the first big issue I have with PowerShell.
The language is very quirky. Simple stuff like using variables is not as intuitive as it should be.
Another issue is encapsulation of logic, it is not straightforward at all. This is my second big issue.
Trying to temporarily disable script policies to run a script is not straightforward either.
It has a very idiosyncratic syntax. The internals are great, but it's so unlike either sh or C that I, for example, just can't be bothered to remember it.
I always wondered why Microsoft didn't just clone something like Bash as close as possible. Powershell was different enough from UNIX that I couldn't get myself interested in it during my phase when I was using both Windows and Linux.
Jeffrey Snover once answered this on Stack Overflow. The answer is that bash and all the other Unix tools wouldn't help you very much on an operating system where things are accessible via an API and not via text files and command-line programs. That's why PowerShell also has "drives" for things like the registry and the certificate store. Even functions, aliases, environment variables and PowerShell variables get their own drive, funnily enough.
"Nushell" has a "TODO" for half the basic features, like flow-control. Can you go into specifics about exactly what Nushell is implementing "so much better?"
Powershell is a mature offering that uses standardized (albeit verbose) naming to allow you to infer what a command should be called Verb-Noun (Get/Set/Start/Stop/etc)-(Process/Service/File/etc).
People are welcome to critique Powershell but more often than not they don't state what the problem actually is.
Yeah, Nushell definitely is not production-ready, though it's still very useful in its current form. My main complaint about PS really is the verbosity.
So far I have avoided Powershell in anything distributed to end users, because execution of unsigned scripts is disabled by default in Windows. It has been easier to use VBScript or BAT files to automate basic tasks, since those scripts can be run unsigned... I suppose it is too much to hope for that Microsoft would now reconsider enabling Powershell script execution by default.
I haven't considered the execution policy such a blocker since you may change it on the powershell.exe command line (for example, run "powershell.exe -ExecutionPolicy RemoteSigned -File script.ps1" from a bat file). Also, the default execution policies changed between PowerShell 5.x, shipped with Windows, and modern PowerShell 7.x, which you need to install separately. In 7.x RemoteSigned is the default in the server environment.
Whatever you have that's calling the Powershell script just has to tell the Powershell system that it's ok to run the unsigned script. The default is just to keep people from double-clicking rando Powershell script files and all hell breaking loose.
In a slightly different universe, CERN gave Tim Berners-Lee a windows workstation instead of a NeXT Cube and www was built on top of Microsoft Word and VBScript.
Just ran into a Y2038 bug in some classic ASP+VBScript code in production the other day. Someone long ago wrote `Date() + 5000` to set an expiry date far in the future (5000 days). As it turns out, 5000 days from now puts us past 1970-01-01 + 2**31 seconds (2038-01-19ish) and that causes VBScript to raise an error and abort the ASP page request with a 500 error.
I raised the issue that we have about 14 years left of ASP+VBScript literally being able to execute properly and calculate dates (sans any large date additions remaining). Guess it'll be sooner than that based on this post but 14 years is definitely the upper bound if your VBScript code even touches dates.
Interesting that VBScript uses Unix time for timestamps. I would have expected something like FILETIME (NT's 1601 epoch) or OLE DateTime, which uses floating point with the integral part referring to days since 1899 and the fractional part is divided into the 24 hours of the day). Windows in general seems to have so many different date/time formats that using Unix time is quite surprising.
Is Microsoft killing the script host or the script itself?
If they're only killing VBscript and not the wscript.exe/cscript.exe scripting host, then Windows probably will still run the jscript variation of a script.
wscript and cscript since XP days and especially 7 have pretty much always been capable of running either pure ES3 or ES5. I think now we're just going to lose the VB style com objects.
But I really don't think we can count on all the related .dlls/COM objects to keep getting support after what is probably their main interface is killed off.
It just doesn't make sense to kill off just vbscript and not most/all of the other stuff that went along with it. I really doubt it's mainly about the language... I think it's about all that script-host/classic asp/COM stuff.
Probably one of the most maddening things I have ever worked with, and that is saying something. Though a huge part of the blame for that goes to COM and registration, interop stuff, which is more Windows than VBScript and also probably never truly going away.
It seems that VBA will continue to exist as the programming front end for MS Office, which is unfortunate. They had announced Python support for Excel a while back and I wish it was better promoted as a viable VBA replacement.