Powershell: Upgrading from v.1 to v.3 - powershell

I have a machine with windows server 2008 and has Powershell v.1, I have a few cron jobs executing a few powershell scripts that run on v.1.
My question is: Will any scripts break if I upgrade to version v.3 or is there version v.4 also?

PowerShell 4.0 exists, but it's not supported on Windows Server 2008 (only R2).
Your scripts should work fine, as PS is backwards compatible, ex. PS 1.0 used Snapins instead of modules, and Snapins is still supported in PS 3.0 / 4.0. But as with any upgrade, you need to test it yourself. PS 3.0 + runs on .Net Framework 4, where some APIs may behave differently then they did in earlier versions.

Related

Can I run PowerShell in version 3 or 4 mode when PowerShell 5 is installed?

I currently have Windows Management Framework 5.1 installed. I want to test that my script works correctly with PowerShell 3 and 4. I am aware of the PowerShell.exe -Version switch but when I try:
PowerShell.exe -Version 3
Or:
PowerShell.exe -Version 4
And then run $PSVersionTable it still shows PowerShell version 5.1 as the running version.
If I run:
PowerShell.exe -Version 2
Then $PSVersionTable does show that the console is now version 2. Why is this?
Windows PowerShell provides a special -Version 2.0 backwards compatibility mode that allows you to run PowerShell version 2 even when you have later versions installed:
The same is not true for all other versions of PowerShell, it is unfortunately not possible to force PowerShell to run as version 3 or 4 when PowerShell version 5 is installed (even though running PowerShell.exe -version 3 will not throw any kind of error/warning message). It is also not possible to have multiple PowerShell versions installed at the same time (with the exception of PowerShell Core which can be installed at the same time as Windows PowerShell).
The only way to test PowerShell scripts with a version of PowerShell (other than 2) is to have alternative installs of PowerShell on separate computers or Virtual Machines.
Windows PowerShell 4.0 and Windows PowerShell 3.0 are designed to be
backwards compatible with Windows PowerShell 2.0. Cmdlets, providers,
snap-ins, modules, and scripts written for Windows PowerShell 2.0 run
unchanged in Windows PowerShell 4.0 and Windows PowerShell 3.0.
However, due to a change in the runtime activation policy in Microsoft
.NET Framework 4, Windows PowerShell host programs that were written
for Windows PowerShell 2.0 and compiled with Common Language Runtime
(CLR) 2.0 cannot run without modification in Windows PowerShell 3.0 or
Windows PowerShell 4.0, which are compiled with CLR 4.0. The Windows
PowerShell 2.0 Engine is intended to be used only when an existing
script or host program cannot run because it is incompatible with
Windows PowerShell 4.0, Windows PowerShell 3.0, or Microsoft .NET
Framework 4. Such cases are expected to be rare.
https://msdn.microsoft.com/en-us/powershell/scripting/setup/starting-the-windows-powershell-2.0-engine

PowerGUI script editor does not recognize the updated powershell version?

I have ARS Shell 1.7.0 installed as part of ARS 6.9 & my MS (windows) powershell version is 4 (obtained by $PSVersionTable.PSVersion, screenshot below)
however when I do the same within the PowerGUI I get version as 2? This has started after i upgraded by shell version to 1.7 from 1.6.9 (PowerGUI worked fine with 1.6.9). I have no clue why is this happening & due to this I'm unable to use any quest cmdlets within the PowerGUI editor which make debugging my scripts an impossible task!
Screenshot from PowerGUI :
I get below error when i try to load ActiveRolesManagementShell from PowerGUI:
UPDATE: tried running Powershell (x86) but still the result is same, can anyone please let me know where in the world is PowerGUI picking up version 2 ?
Updated the PowerGUI Script editor to version to 3.8 & it resolved the issue. PowerGUI now recognizes v4
People using ver 3.2 should make a note of it.
I think the issue might be due to a change in ARS 1.7.0 that is forcing the PS2 engine to be required, per this:
Windows PowerShell 4.0 and Windows PowerShell 3.0 are designed to be
backwards compatible with Windows PowerShell 2.0. Cmdlets, providers,
snap-ins, modules, and scripts written for Windows PowerShell 2.0 run
unchanged in Windows PowerShell 4.0 and Windows PowerShell 3.0.
However, due to a change in the runtime activation policy in Microsoft
.NET Framework 4, Windows PowerShell host programs that were written
for Windows PowerShell 2.0 and compiled with Common Language Runtime
(CLR) 2.0 cannot run without modification in Windows PowerShell 3.0 or
Windows PowerShell 4.0, which are compiled with CLR 4.0. The Windows
PowerShell 2.0 Engine is intended to be used only when an existing
script or host program cannot run because it is incompatible with
Windows PowerShell 4.0, Windows PowerShell 3.0, or Microsoft .NET
Framework 4. Such cases are expected to be rare.
Many programs that require the Windows PowerShell 2.0 Engine start it
automatically. These instructions are included for the rare situations
in which you need to start the engine manually.
https://msdn.microsoft.com/en-us/powershell/scripting/setup/starting-the-windows-powershell-2.0-engine

Is there a way to enforce/test Powershell 1.0 compatibility on a machine with a higher version installed?

I have a powerscript that when I distribute it I would like to ensure works even if powershell 1.0 is the only version installed. While there is a way to run other versions of PS side-by-side, there doesn't seem to be so for 1.0.
Running ...\powershell\1.0\powershell or
powershell -version 1.0
both result in the $PSVersionTable.PSVersion command still working in my development environment (where it should fail as the $PSVersionTable doesn't exist in 1.0).
Is there another way to get a powershell 1.0 sandbox?
As you need PowerShell V 1.0 on your network, that is because you still have Windows XP or Windows Server W2K3 working on your network.
The think I do is to install PowerShell V1.0 on the top of an XP VM.

How to upgrade PowerShell version from 2.0 to 3.0

The OS that I am using is Windows 7, and the PowerShell version that is installed here is 2.0. Is it possible for me to upgrade it to version 3.0 or 4.0?
Because there are cmdlets that version 2.0 can't recognize.
Download and install from http://www.microsoft.com/en-us/download/details.aspx?id=34595. You need Windows 7 SP1 though.
It's worth keeping in mind that PowerShell 3 on Windows 7 does not have all the cmdlets as PowerShell 3 on Windows 8. So you may still encounter cmdlets that are not present on your system.
The latest PowerShell version as of Sept 2015 is PowerShell 4.0. It's bundled with Windows Management Framework 4.0.
Here's the download page for PowerShelll 4.0 for all versions of Windows.
For Windows 7, there are 2 links on that page, 1 for x64 and 1 for x86.
Just run this in a console.
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
cinst powershell
It installs the latest version using a Chocolatey repository.
Originally I was using command cinst powershell 3.0.20121027, but it looks like it later stopped working. Since this question is related to PowerShell 3.0 this was the right way. At this moment (June 26, 2014) cinst powershell refers to version 3.0 of PowerShell, and that may change in future.
See the Chocolatey PowerShell package page for details on what version will be installed.
Install Chocolatey
Run the following commands in CMD
choco install powershell
choco upgrade powershell
As of today, Windows PowerShell 5.1 is the latest version. It can be installed as part of Windows Management Framework 5.1. It was released in January 2017.
Quoting from the official Microsoft download page here.
Some of the new and updated features in this release include:
Constrained file copying to/from JEA endpoints
JEA support for Group Managed Service Accounts and Conditional Access Policies
PowerShell console support for VT100 and redirecting stdin with interactive input
Support for catalog signed modules in PowerShell Get
Specifying which module version to load in a script
Package Management cmdlet support for proxy servers
PowerShellGet cmdlet support for proxy servers
Improvements in PowerShell Script Debugging
Improvements in Desired State Configuration (DSC)
Improved PowerShell usage auditing using Transcription and Logging
New and updated cmdlets based on community feedback
The latest PowerShell version as of Aug 2016 is PowerShell 5.1. It's bundled with Windows Management Framework 5.1.
Here's the download page for PowerShell 5.1 for all versions of Windows, including Windows 7 x64 and x86.
It is worth noting that PowerShell 5.1 is the first version available in two editions of "Desktop" and "Core". Powershell Core 6.x is cross-platform, its latest version for Jan 2019 is 6.1.2. It also works on Windows 7 SP1.
do use the links above. If you run into error "This update is not applicable to your computer. " then make sure you are in fact using the right file for your os. for example i tried running windows 2012 server from that link on windows 7 service pack 1 and I got the above error so be sure to use the right zip. If you don't know which os you have then go to start and system and it should pop right up This should be self explanatory but

Do all script users need Powershell installed?

Looking to use Powershell for writing some scripts. The concern is, do all users of the script need Powershell installed on their computer in order to have the script execute properly? Is the behavior different for Windows 7 vs. XP vs. 2k etc? I understand powershell is included in 8, so that's not a concern.
PowerShell is also included in Windows 7. PowerShell might be included in XP not sure on that. I'm pretty sure 2k does not have PowerShell. Yes, if you want to run a PowerShell script you will need to have PowerShell installed. Just like you would need Python installed if you want to run a Python script.
I know that Win 7 comes with PS version 2.0 by default. Not sure on XP. The current version is PS is 3.0 it comes with the Windows Management Framework (WMF) 3.0.
During December 2012 Microsoft had the WMF 3.0 deployed as an update but recalled it a couple of weeks later because there was some compatibly errors with other stuff.
I'm using PS 3.0 and updating all my computers to PS 3.0. PS add new stuff that I want to learn.