Can't use out-gridview since installing PowerGUI with Powershell V3 - powershell

Just wondering if anyone seen this and knows a workaround.
I'm Running Windows 7 64bit and just upgraded to Powershell V3. Since then, i can't use out-gridview commands. I get the following error.
To use the Out-GridView cmdlet, install the Windows PowerShell Integrated Scripting Environment feature from Server Manager. (Could not load file or assembly '
Microsoft.PowerShell.GraphicalHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file sp
ecified.)
I have opened the native MS ISE and can run out-gridview withgout error.

PowerGUI Script Editor launches using PowerShell v.2, even though you have PowerShell v.3 installed. Launching Script Editor with the "-version 3.0" option resolved this problem for me.

There are two things you can check:
When you installed PowerShell V3, did you also make sure to install the PowerShell Integrated Scripting Environment (ISE).
Make sure you have Microsoft .NET Framework v3.5 with Service Pack 1 installed also.
Source of answer

I fixed it by changing -Version 2.0 to -Version 3.0
Right click on Exchange Management shell and choose properties. Find above in TARGET.

Related

PowerShell ISE: how to run new PowerShell version

How can I get PowerShell ISE to work with PowerShell 6.0. Currently, it has 4.0.
This server has PowerShell 4.0 installed and I installed PowerShell 6.0 with PowerShell-6.1.0-win-x64.msi from this link: https://github.com/PowerShell/PowerShell/releases
The files now exist in C:\Program Files\PowerShell\6.
However, ISE still shows 4.0, but I need it to run 6.0
$PSVersionTable.psversion
Major Minor Build Revision
4 0 -1 -1
PowerShell has 3 executables...
Windows only...
PowerShell_ISE.exe = ISE v2 - v5.1
powershell.exe = consolehost v1 - 5.1
Note: (there are no new versions coming, but this will be supported going forward as it is today, as per Microsoft announcements, just nothing new coming to it. Just bug /security fixes.)
Cross-platform
pwsh.exe = PowerShell Core/v6
The editor to use if you are using v6 is Visual Studio Code, which is also cross-platform, unlike the ISE.
https://code.visualstudio.com/Download
The are no plans to make the ISE leverage pwsh.exe/PSCore.
However, you can continue to use the ISE, and if you need something specifically to leverage PSCore, you have to shell out to it just as you would to cmd.exe. Your code will run the pwsh.exe console, and return you back to the ISE, depending on how you shell out to it.
What you are using is Windows PowerShell ISE which is always has Windows PowerShell as the integrated shell, you need VSCode here, where you can select which version of PowerShell to use ...
Just need to change below item in File -> Preferences -> Settings.
"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\pwsh.exe"
Same can be done via UI in few clicks as well...

How to Import Nuget Module to powershell script [duplicate]

I was trying to use my favorite source control from the Package Manager console in Visual Studio 2010. I had issues described in another topic. For now the best answer is to move all command-line stuff from Visual Studio to bare PowerShell.
But this case the Visual Studio related commandlets are not working. For example, most crucial one — I cannot run Update-Database command from Entity Framework.
Is it possible to register somehow Visual Studio specific commandlets for the current project in PowerShell? Or make PowerShell automatically take current project context from the packages subfolder?
The NuGet PowerShell commands rely on being run from within Visual Studio so will not work outside in the normal PowerShell running from the command line.
You can however use migrate.exe which ships with the EntityFramework NuGet package and use that from the command line to update your database.
As a prototype I put together a way to use NuGet PowerShell commands from the normal PowerShell command line using SharpDevelop. Unfortunately at the moment the EntityFramework NuGet package does not work with SharpDevelop.
Another interesting project is StudioShell which provides a new DTE: drive inside Visual Studio but can also be used outside from the command line. I do not believe it supports NuGet PowerShell commands being run from the normal PowerShell command line.
I can find the NuGet.psd1 file at:
C:\Program Files (x86)\Microsoft Visual Studio
12.0\Common7\IDE\Extensions\5ttpefif.3mk\Modules\NuGet\NuGet.psd1.
However, when you try to load it:
PS> Import-Module $pathToNuGetPsd1 -Force -NoClobber -Scope Global
Import-Module : The name of the current Windows PowerShell host is: 'ConsoleHost'.
The module 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\
Extensions\5ttpefif.3mk\Modules\NuGet\NuGet.psd1' requires the following Windows
PowerShell host: 'Package Manager Host'.
I think we're out of luck. It has to be run from the Package Manager Host and requires things from Visual Studio as stated by Matt.
To solve my problem I used Chocolatey to install NuGet.CommandLine and then used NuGet.bat to do what I needed. It is a little more work and may not work in all cases depending on what you're trying to do.
Chocolatey: https://github.com/chocolatey/chocolatey/wiki/Installation
NuGet.CommandLine:
PS> cinst NuGet.CommandLine
I'm not terribly familiar with the Visual Studio cmdlets, but you can import a module into your PowerShell session by using Import-Module -Name <ModuleName>. You can list the available (aka. "installed") PowerShell modules by using `Get-Module -ListAvailable'.
My guess would be that the Visual Studio cmdlets are contained with its own PowerShell module, but it's quite possible that it's not "installed" to one of the standard locations in $env:PSModulePath. If this is the case, then you might need to locate the module directory and import either the .psd1 or .psm1 file directly, and pass that into: Import-Module -Name <FullPathToModuleFile>.
As an example of the above, take notice of where the Windows Azure PowerShell module is located: http://trevorsullivan.net/2012/06/07/introducing-microsofts-official-windows-azure-powershell-module/
It's under the Program Files directory, and is not immediately available to PowerShell, unless you import the module from its fully qualified path (the .psd1 module manifest file).
Hope this helps.

PowerShell IntelliSense targeting older versions of PowerShell

Newer versions of the PowerShell ISE (and third-party PowerShell scripting environments like PowerGUI) offer pretty good IntelliSense support.
However, I often write scripts that I want to run on servers which only have older versions of PowerShell installed (in particular, PowerShell 2.0 on Windows Server 2008 R2). I can't upgrade the PowerShell installation on the server and the PowerShell 2.0 ISE doesn't have IntelliSense.
Is there any way to configure the PowerShell 3.0 or 4.0 ISE, or PowerGUI (or any other free PowerShell script editor!) to provide IntelliSense which is restricted to PowerShell 2.0 compatible code only?
I have confirmed Jason's theory that Intellisense does work in PSRemoting against the installed version of Powershell, but it looks a bit different. I tested using Powershell preview build 5.0.10018.0 remoting to Server 2008R2 with PS v2.0. I ran:
$Procs = Get-Process
$Procs <Ctrl + Space>
This resulted in an Intellisense tooltip with options like:
$Procs.count
$Procs.Clear(
Where v3.0 and up would only include the property or method names, not the variable itself.
I also tested for the .Where() and .Foreach() magic methods which did not show up in Intellisense. This seems to confirm that it's working against the installed version.

Can I install Powershell 4 side by side with Powershell 3?

I have Powershell 3 installed on my box.
I need to test some scripts with Powershell 4 but I want to continue to run some of my scripts that are tested under Powershell 3 and I do not want to break something by installing Powershell 4.
QUESTION:Is it possible to open a Powershell sessions under Powershell version 3 (or even 2 if needed) despite I have installed Powershell 4?
When you have the Windows Management Framework Core 4.0 package installed, you can run PowerShell version 2.0, but not 3.0. Use the -version 2.0 parameter to launch PowerShell v2.
See this TechNet article: http://technet.microsoft.com/en-us/library/hh847899.aspx
Also see the help about_powershell.exe help documentation: http://technet.microsoft.com/en-us/library/jj553275.aspx
Yes. Starting with V3, you could open a powershell session for a downlevel version using the -Version parameter.
-Version
Starts the specified version of Windows PowerShell.
Enter a version number with the parameter, such as "-version 2.0".
So running
Powershell.exe -Version 2
will start a session that can be used to run/test a V2 script.

What free Powershell editors can I use on Windows XP SP2?

I have Windows 7 at home with Powershell 2 and I really like the free version of the PowerGUI Powershell editor.
I'd like to start using Powershell at work but we are on version 1.o on XP with SP2. I was going to install PowerGui but
it looks like it requires some Core components or maybe even Powershell 2.0. I expect that our XP production servers may not have this version and I think it is safe to stay with 1.0 for now to avoid pushback from the keys with the keys to the production box.
My question is this:
Is there an editor like powerGui that I can use with version 1 where I do not have to install additional Powershell components that may not be present in production?
You can use all of the free and commercial editors on XP:
PowerShell Integrated Scripting Environment (ISE) ships with PowerShell V2
PowerGUI (www.powergui.org) is a great free editor with support for code folding and intellisense, and PowerPacks to make it easy to work with PowerShell by point and click
Idera makes another great editor (PowerShell Plus - www.powershellplus.com) with a strong collection of scripts that ship with it.
DevFarm makes PowerWF and PowerSE (www.powerwf.com), and editor and workflow tool for working with PowerShell
PrimalForms is an editor and tool to make UI in PowerShell, built by Sapien (www.sapien.com)
Hope this Helps
If your question is actual PowerGUI script editor (version 2.4.0) works with PowerShell V1.0. My answer is that I don't think it works. In my understanding you need a version before 2.0 . I'am using PowerGUI 1.9.5.966 which works perfectly with PowerShel V1.0.