0

I'm looking for a sort of history lesson. I'm a latecomer to PowerShell. I learned on version 4 and I have a growing number of commandlets that I'm contemplating using in places where version compatibility matters. Most of my unit tests are passing when I run powershell -version 3. On the other hand, there is a sea of red when I run powershell -version 2. Rather than blindly reworking my code-base to try to make it friendly to pre-v4 versions of PowerShell, I'd like to get some sort of understanding what that would entail.

There are some posts that speak to some differences between versions, but I haven't found anything canonical, nor have I found any that take the retrospective perspective needed to undertake making a codebase backward compatible.

Here are my specific questions:

  1. What are the major things missing from earlier versions of PowerShell that code written for later versions are probably relying on?

  2. Are versions of PowerShell itself backward-compatible? That is, if a well-written script runs correctly on version 2, can I expect it to behave the same way when run on versions 3, 4, and 5?

alx9r
  • 3,675
  • 4
  • 26
  • 55
  • 1
    There is way too much to cover here in a simple question. A _basic_ comparison can be found [here](http://en.wikipedia.org/wiki/Windows_PowerShell) as it shows you what has been added over the years. Also I am not aware of any powershell that is not forwards compatible. Do we edit this question where v6 comes out? – Matt May 04 '15 at 19:04
  • @Matt There are definitely scripts that were legal in v2 that do not behave the same in v3+, for example: `foreach ($a in $null) { write-host "a:$a" }` will output a single line in v2 but nothing in v3+. In short, in version 2, null was treated as a collection of a single item containing null, whereas in version 3 onwards it is treated as an empty collection. – Mike Zboray May 04 '15 at 19:20

1 Answers1

1
  1. This question is too broad to get a good answer. I would suggest reading What's New in Windows PowerShell to get the highlights of what's changed.
  2. PowerShell is backwards compatible with scripts written for earlier version of PowerShell. I won't say 100%, but I can't remember having heard of any problems. Newer versions have extended and simplified existing cmdlets and introduced a lot of improvements, but AFAIK nothing has been removed or broken. Even Snap-ins are still supported in 5.0 even though they were replaced by modules in PowerShell 2.0.
Frode F.
  • 52,376
  • 9
  • 98
  • 114