5 ms·
| You have that guarantee starting with Windows 7. Version is one thing; some nice things are available only in v3+, but v2 is very usable already. I love me s
by tbyehl 12y ago
| You have that guarantee starting with Windows 7. Version is one thing; some nice things are available only in v3+, but v2 is very usable already.
I love me some Powershell. Wrote my first non-trivial PS script in early 2010 that was a major component to building something I would now call "Continuous deployment of Windows OS images."
But I still have way more lines of BAT in production than PS1 because the versioning is a nightmare. v2 was the first really usable release and it ran everywhere I cared about except for Windows PE. v3 got some nice enhancements and support for Windows PE, but dropped support for anything older than Windows 2008. v4 added some more but took away Windows 2008 R1.
If it were just that newer versions of Powershell offered new modules and cmdlets it wouldn't be such a big deal, but the syntax itself has been evolving. This is valid in PS v3+ but not in PS v1/2:
Get-Alias | ? Definition -eq Where-Object
For PS v1/2 you'd have to write it as:
Get-Alias | ? { $_.Definition -eq "Where-Object" }
Many landmines are out there waiting if you need to write a script that can handle multiple Powershell versions.
There are plenty of sucky things about BAT files... But they are truly lowest-common-denominator on any Windows system, there aren't any syntactical landmines waiting to get you with different Windows versions since 2003, and for anything you want to do on Windows that you can do with Powershell you will certainly be able to find a command-line tool that lets you do the same thing with Batch.
- ygra 12y agoThis is not an example of evolving syntax. It's just a bunch of parameter sets added to Where-Object. New syntax is the -in operator for example (reverse of -contains). However, I find myself using the new parameter sets for Where-Object very infrequently. Since they can only model Property -Operator Value their use is limited to certain operations, which I find myself to need not that often. And if the conditions get more complex I need to write a scriptblock anyway, having to refactor your former form into the latter.
- tbyehl 12y agoPoint being that it's easy to write a script that works fine on v3/4 but fails when run on v2, without doing something incredibly obvious like using cmdlets or modules that didn't ship with v2. Here is a by-no-means-comprehensive list of potential gotchas: • Operation Statements vs Script Blocks • Several new operators • Changes to $PSScriptRoot and $MyInvocation • Stop parsing symbol --% • Ordered dictionaries • New redirection operators • Count and Length properties added to "arrays" of zero or one • Retrieving a property from a collection that only exists in the individual items returns the value from all items. • BadNumericConstant