Powershell Version 2 - Got it working and would like to discuss

I have read on blogs, forums and mailing lists that Powershell Version 2 will not be supported however I had a need to support Powershell 2 in my environment and spent some time looking at what it would take to make it work with version 2 of Ansible. Currently I have it working on 2.0.0.2 and will test the changes with 2.0.1.0+ tomorrow. Minor changes to winrm.py and powershell.ps1 were made to make it work and then when testing all core modules there was a few places where some of the methods for getting data had to be changed to make most of them work successfully. Powershell 3,4 still works with the minor changes.

Please let me know if you are interested in these changes and want to discuss more on what was done to get it to work.

-Eric

Tested with my environment which includes:
Windows XP Pro 32-Bit
Windows 7 Pro 32-Bit
Windows 7 Pro 64-Bit
Windows 8.1 Update 1 32-Bit
Windows 8.1 Update 1 64-Bit
Windows 10 32-Bit
Windows 10 64-Bit
Windows 2003 SE 32-Bit
Windows 2003 SE 64-Bit
Windows 2003 EE 32-Bit
Windows 2003 EE 64-Bit
Windows 2008 SE 32-Bit
Windows 2008 SE 64-Bit
Windows 2008 SE R2 64-Bit
Windows 2008 EE 32-Bit
Windows 2008 EE 64-Bit
Windows 2008 EE R2 64-Bit
Windows 2012 SE 64-Bit
Windows 2012 SE R2 64-Bit

Hi Eric,

The decision to require PS3 at a minimum was made before I got here, but in general I don’t disagree with it. While I’m morbidly curious, I’d have a lot of concerns about supporting PS2 generally. The biggest few off the top of my head:

  • We’d no longer be able to assume the presence of .NET 4.0, which hampers a number of planned core Windows enhancements.
  • Increased testing matrix (we’re already planning ~5 target environments for Windows CI with PS3/4/5 and Server 2008R2, 2012R2, 2016).
  • Missing cmdlets and functionality for existing important Windows modules

That said, we could look at supporting just enough PS2 in the core connection infrastructure and actions/modules to support bootstrapping to PS3+ via Ansible. Do you have the updated code posted somewhere?

-Matt Davis (Ansible Core Windows Lead)

Yeah, I likewise have some concern about attempting to support too old a baseline version, as it might tie us to problems if/when language features are removed and we have trouble supporting newer versions of the language (pretty much what we’re dealing with on the Python 2.4->3+ front now).

Considering most of the OS’s on that list are EOL, I’m not sure what the effort would gain us.

Hi Matt,

I just finished merging the changes into 2.0.1.0 and will be finishing testing/committing them to github later today. I 100% understand the desire to have the latest PS version supported and the issues with having to support PS2 going forward would not be the best use of time for the project. Long term I have even thought about just keeping a side install running for boxes that require PS2 or using PS2 specific modules if the winrm.py, powershell.py and powershell.ps1 changes could be considered acceptable. The PS2 requirement is only for XP/2003 and Windows 2008/7 running Microsoft specific applications below these versions Exchange 2010 SP3, SharePoint 2010 without the latest workaround for management tools, and System Center 2012.

-Eric

Matt,
The code is uploaded as well as the changes to the setup.ps1, win_copy.ps1, win_stat.ps1 under the stable-2.0 branch within the following repos.

https://github.com/elum/ansible
https://github.com/elum/ansible-modules-core

-Eric

Hi Eric.
I am very interested in what you had to do to get powershell 2 working with Ansible.
I am in a situation where I still have a LOT of Windows 2008 R2 out there that still have powershell 2 installed.
I’d love to know which changes you had to make to get it to work.

Thx

  • Herman -

I’d suggest using the upgrade_to_ps3 script mentioned here http://docs.ansible.com/ansible/intro_windows.html#getting-to-powershell-3-0-or-higher on your s2008r2 machines.- powershell 2 pre-dates the remote management via web services stuff… You can just about get a remote shell with ps2 but the capabilities will be very, very limited. Be aware that there’s also a hotfix need on s2008r2 /WMF 3.0 http://support.microsoft.com/kb/2842230 (also mentioned on the same page).

Jon

There are tools coming in Ansible 2.3 that should also help to do mass upgrades of PS2 hosts (eg, become/runas, win_psexec). The underlying WinRM exec wrapper in 2.3 has greatly increased reliance on Powershell 3 and .NET 4 (which is why we didn’t want to support back to PS2 in the first place), so especially if you want to use anything new that’s happening in Ansible, I’d suggest looking into upgrading to at least PS3 (though PS5 is supported on 2008R2, and supposedly a much simpler upgrade path than 3 or 4, just sayin’). Unless you’ve got some obscure technical reason not to upgrade, you should be able to do it en-masse with Ansible. :slight_smile:

-Matt