Application using PowerShell System.Management.Automation compiled on Windows 8 not working on Windows 7 - powershell

I built a powershell script runner on windows 8 using VS2012 and Framework 4.0 and when I launch the runner on windows 7 it gives me an error because the powershell version is older that the one on windows 8. (Win7: PS2, Win8 PS3). (System.Management.Automation)
Are there any solutions besides recompiling the application on windows 7 or installing powershell 3 on windows 7? (Or upgrading my windows 7 machine :P) Thanks!

You can reference the PowerShell 2.0 version of the assembly (v1) from your project on Windows 8. Compiling with that version will make it work on Windows 7 (PowerShell 2.0) and Windows 8 (PowerShell 3.0).
To get the PowerShell v2.0 version of this assembly you could pull it from the GAC or install the PowerShell 2.0 SDK and use that.
Also make sure your project targets .Net 3.5 for it to work on Windows 7 without having to install .Net 4.5.

Related

How to upgrade windows powershell 5.0 to 5.1

How to upgrade powershell from 5.0 to 5.1 in windows 10?
To do this I believe you need to upgrade Windows 10 itself, to the Anniversary Edition (or later). I don’t think you can directly install WMF 5.1.
The direct installer for WMF 5.1 is just for Windows 7 Service Pack 1, Windows 8.1, Windows Server 2008 R2, Windows Server 2012 and Windows Server 2012 R2.
The default powershell in window 10 is 5.1, you can check it by $PSVersionTable, even if you dont have ps 5.1, you can try instal WMF5.1 from this location https://www.microsoft.com/en-us/download/details.aspx?id=54616, for details visit https://learn.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-5.1

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

Powershell: Upgrading from v.1 to v.3

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.

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