Run PowerShell.exe - Version 2.0 Causes ISE to Hang

Just starting to learn.

Why does the PowerShell.exe -Version 2.0 command “hang” when executed in PowerShell_ISE ?

From trial-and-error, the console is the choice to work with version 2.0 ?

Since you are saying, you are just starting to learn. It is really important that you get a good baseline understanding before you unnecessarily frustrate yourself. See the plethora of examples / options below.

Are you saying, you are in the ISE, and then going to the ISE output / console Window and trying to change the ISE session to v2?

That’s really not a thing you can do. You put the version in your script not like what it seems like you are trying.

The ISE console is not for interactive console commands (.exe, etc). So, cmdlets and scripts only, PowerShell, as you are using it is calling the powershell.exe console host and it expects user interaction, just as Nslookup, etc would.

What are seeing has nothing to do with v2, but everything to do with calling an interactive command line tool.

Console Application (Non) Support in the ISE

There are some limitations on how the ISE interacts with console applications you need to be aware of, for apps like ftp and netsh.

First of all, the ISE Runs console apps that don’t require user input just fine.
For example, “ping www.microsoft.com” and “cmd /c dir /s”

Piping also works fine in the ISE,
For example, PS C:\Users\ibrar> “show mode” | netsh
netsh>online

Automation in scripts, that don’t require user interventions should be fine.

However, if you run “cmd /k” which requires input, the ISE will be stuck, and you’ll have to stop the pipeline, using Ctrl-Break or pressing the stop button.

Console Application (Non) Support in the ISE - PowerShell Team

    
    $psUnsupportedConsoleApplications

    wmic
    wmic.exe
    cmd
    cmd.exe
    diskpart
    diskpart.exe
    edit.com
    netsh
    netsh.exe
    nslookup
    nslookup.exe
    powershell
    powershell.exe

You can run them, but you have to pass all possible parameters needed. Again, no interactive keyboard stuff with allowed.

So, if you are writing script that require you use v2, then you have to ensure you only use v2 code in your script and use the -version check in the script itself.

See:

About Requires

SHORT DESCRIPTION
Prevents a script from running without the required elements.

LONG DESCRIPTION
The #Requires statement prevents a script from running unless the Windows PowerShell version, modules, snap-ins, and module and snap-in version prerequisites are met. If the prerequisites are not met, Windows PowerShell does not run the script.

You can use #Requires statements in any script. You cannot use them in functions, cmdlets, or snap-ins.

about Requires - PowerShell | Microsoft Learn

#requires your scripts

Recently, I saw someone that had developed a script on the CTP3 drop and was then having trouble running it on v1 of PowerShell. Eventually it turned out that he was using v2 features in his script. Most of you know that we are trying to keep the next version of PowerShell compatible with v1 and I encourage you to report any problems that you might have in that area. Unfortunately, v2 being compatible with v1, doesn’t mean v1 is compatible with v2.

#requires your scripts - PowerShell Team

### Learning PowerShell Resources

There are lots of solid references available. What are the best is a matter of opinion. This is why rankings on books, say on Amazon and other sites that allow user ratings vary can vary wildly. You too will have your take on the topics when you read them. My suggestion is first do some - free - live video beginner training via Microsoft virtual academy, and even on Youtube. Be sure to follow the authors blogs mentioned in the references below as well.

Examples:

— Microsoft Virtual Academy —
Training | Microsoft Learn
Training | Microsoft Learn&lang=1033’
Getting Started with Microsoft PowerShell | Microsoft Learn
Getting Started with Microsoft PowerShell | Microsoft Learn

— Microsoft Channe9 —
Getting Started with PowerShell 3.0 | Microsoft Learn
Shows | Microsoft Learn&lang-en=en&pubDate=year’

— Youtube —
'www.youtube.com/watch?v=wrSlfAfZ49E
www.youtube.com/results?search_query=beginning+powershell
www.youtube.com/results?search_query=powershell+ise+scripting+for+beginners

— eBooks —
powertheshell.com - powertheshell Resources and Information.
powershell.org/ebooks
Effective Windows PowerShell: The Free eBook | Keith Hill's Blog
Veeam: Free Virtualization White Papers
Reddit - Dive into anything
blogs.technet.microsoft.com/pstips/2014/05/26/free-powershell-ebooks
www.idera.com/resourcecentral/whitepapers/powershell-ebook
mikefrobbins.com/2015/04/17/free-ebook-on-powershell-advanced-functions

— Windows PowerShell Survival Guide —
Purpose of this Document
The purpose of this document is to help you to learn more about PowerShell and to be successful in applying it. This document seeks to point to the best content on the web to enable you to reach that goal.

Scope of this Document
This page contains links to help you learn more about Microsoft Windows PowerShell. This includes PowerShell fundamentals as well as how PowerShell is used in Windows applications and services. As long as it’s PowerShell related, we’ll try to point to it! The document is also version agnostic, and contains information about current and future versions of PowerShell.

social.technet.microsoft.com/wiki/contents/articles/183.windows-powershell-survival-guide.aspx

— Book(s) to leverage —

Beginning —

Learn Windows PowerShell in a Month of Lunches 3rd Edition
Donald W. Jones (Author),‎ Jeffrey Hicks (Author)
ISBN-13: 978-1617294167
ISBN-10: 1617294160

Internediate —

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft’s Command Shell 3rd Edition
Lee Holmes (Author)
ISBN-13: 978-1449320683
ISBN-10: 1449320686

Advanced —

Windows PowerShell in Action 3rd Edition
by Bruce Payette (Author),‎ Richard Siddaway (Author)
ISBN-13: 978-1633430297
ISBN-10: 1633430294

— And start with lots of examples. —
'www.powershellgallery.comBrowse code samples | Microsoft Learn
Scripting Blog [archived] - Formerly known as the "Hey, Scripting Guy!" blog

Thoroughly read / re-read and understand built-in the help files and review all the scripts on your machine.

# Get parameters, examples, full and Online help for a cmdlet or function

(Get-Command -Name Get-Content).Parameters
Get-help -Name Get-Content -Examples
Get-help -Name Get-Content -Full
Get-help -Name Get-Content -Online

Get-Help about_*
Get-Help about_Functions

# Find all cmdlets / functions with a target parameter
Get-Help * -Parameter Append

# All Help topics locations
explorer "$pshome\$($Host.CurrentCulture.Name)"

— Take a online / in-person class —
There are many 3rdP academic vendors that will come to your site to deliver a class, online providers, or your folks could attend a Microsoft Official Curriculum course on the topic, or use all the free stuff online. Either way, the need to commit to the effort.

— Lastly —
Learn by doing, not just reading. Use PowerShell every day. If you find yourself jumping to cmd.exe, stop, and switch to PowerShell.
Don’t make up scenarios, follow some of the forums and try to see if you can resolve the questions being asked.

1 - Everything you’d normally do at the DOS command prompt or VBScript, etc…
start doing all that in the PowerShell ISE or PowerShell Console host or Visual Studio Code using the PowerShell Extension. Using only the normal DOS commands and then do the same with the cmdlets which do the same thing.

Windows PowerShell equivalents for common networking commands (IPCONFIG, PING, NSLOOKUP)
blogs.technet.microsoft.com/josebda/2015/04/18/windows-powershell-equivalents-for-common-networking-commands-ipconfig-ping-nslookup

Know that interactive DOS commands don’t work in the PowerShell ISE natively. You can make them work.

See Using Windows PowerShell to run old command line tools (and their weirdest parameters)
Using Windows PowerShell to run old command line tools (and their weirdest parameters) | Microsoft Learn

Note: Sometimes it is just easier to use the old DOS commands, even in PowerShell scripts, because though they may not be as flexible, they are more concise. I wrote a function that allows me to do this sort of stuff to avoid having to type all this stuff all the time.

2 - Read the help files and about_* files, leverage the examples in the help files. Tweak the examples in the help files.

3 - Use any Windows tool that will write the baseline code for you (which you can then tweak), such as the Windows Server 2012 ADAC console leveraging the PowerShell History Viewer.

Active Directory Administrative Center: Getting Started
Active Directory Administrative Center: Getting Started | Microsoft Learn

Active Directory Administrative Center
Introduction to Active Directory Administrative Center Enhancements (Level 100) | Microsoft Learn

Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2
Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2 | Microsoft Learn

4 - Make a copy of…

C:\Windows\System32\WindowsPowerShell\v1.0\Modules

… then, open the scripts, modules, functions in the default Windows PowerShell folder, in the PowerShell ISE or VSCode and review that’s going on in them. Make a copy of them to play with and tweak. Also look for any other location that has .ps files, make a copy and review.

5 - You can also directly look at many of the function code in PowerShell by doing this approach…
Spying on Function Source Code
Spying on Function Source Code | IderaBlog

6 - Get real familiar with the PowerShell Snippets feature. press CTRL+J to see what is there.

7 - Other MS produces and 3rdP vendor products, will show the PowerShell code they are using under the covers. As you use the Window GUI’s pause a minute to look for the code on the screen and copy and save that off for your review.

8 - Continue the video training, MVA, ‘Shows | Microsoft Learn’, YouTube, Plural, etc.

9 - Keep a library of everything you find in a central location, OneNote, doc, or your own module for easy recall / research.

I am starting to learn that is why I am here asking questions looking for answers that clarify my questions and not ones that make things more confusing. I have Don Jones’s text and I am asking questions based upon text within his book.

I do not need to be bombarded with education resources. I have Don Jones’ text and I am focused on learning the fundamentals using only that text and getting answers to my questions here.

I just need very specific answers to very specific questions that I am asking based upon what I am seeing in that single text.

ISE is not for interactive use. I do not understand “interactive.”

See my updates, and no that link is still live. I always check links before I post them.
And btw, I spend 95% of my time in the ISE daily. Yet, I still use other tools, like I point to in this reply.
You can do interactive efforts in the ISE, as long as they are PowerShell cmdlets, scripts, or command line tools that you know all the parameters / switches for. However, the ISE is first a foremost a scripting environment. If you are doing generic command line interactive stuff, stick with the powershell.exe console or the other option I point to below.

Interaction, means, that after you type *.exe command, it will either spit out a result or expect something else from you in order to continue. Hence interaction. Since you are already in the ISE PowerShell console, you cannot use the powershell.exe console in the ISE console. They are two different environments.

Simply put, you can’t use .exe/.com/.bat, etc., commands in the ISE console host, that prompt for you to do something.
The hang, is really not a hang, but a pause by the executable your are trying to use, waiting for you to input something else.

Try it. Restart the ISE, and in the ISE console, type nslookup. The same this will happen. Then start just the default powershell.exe console and type nslookup again, and see the difference.

If you want to use a scripting editor that allows you to use the full powershell.exe console, vs the ISE console, download and use MS Visual Studio code instead of the ISE.

'code.visualstudio.com'

ISE and VSCode have their strengths and weaknesses, you have to try both and choose which works for you best.
Note the ISE is a Windows only thing, where as VSC is Windows/OSX/Linux. Just also note the PowerShell version in OSX and Linux is not the same as on Windows.
Also, note, that ISE as it is today, will be this way for the foreseeable future. It will be around, just like DOS, but no further work is going into it. All the work is going into VSC. Yon can setup VSC to get close to how the ISE works, but not 100%.

See this article.

How to install Visual Studio Code and configure it as a replacement for the PowerShell ISE

If you follow me on Twitter, then I’m sure you’re aware that I’ve been using nothing but VS Code (Visual Studio Code) as a replacement for the PowerShell ISE (Integrated Scripting Environment) for the past couple of weeks and while I had tried it in the past, I didn’t previously think it was ready for prime time. That’s now changed with all of the updates and work that has gone into it. From what I’ve found, it works fairly well flawlessly so I’ve created a short and simple video to help others get VS Code installed and configured as a replacement for the PowerShell ISE.

How to install Visual Studio Code and configure it as a replacement for the PowerShell ISE | mikefrobbins.com

postanote - thank you much for your answers. The explanation of “interactive” was most helpful.

Absolute n00b. And when I say that I mean Windows Home n00b - as in a very basic Windows user. At the bottom. There’s only one direction. Up.

PS - I followed your advice to grab Don Jones’ book “Learn Windows PowerShell in a Month of Lunches”. And that is where I am starting.

8^}

No worries. Welcome to the Windows and PowerShell. This will be a journey for you. Frustration will abound, but all learning is about try/fail/recover/continue. After more than 4+ decades doing this stuff, that try/fail/recover/continue, is still and will always be a thing we have to deal with.

As far as the educational bombardment. I been delivering IT PRO / Developer / Security course (well outside of my day job) since the 1980’s and I am a firm believer in never just use one source. The sources I listed are the info I give all my PowerShell / Infrastructure students at the very beginning of the class and remind them of it again at the end.

So, not trying to overload you, but just an edification. PoSH is very powerful and you should have various resources to gain as much insight as you can. Listening to only one voice is limiting your full breath learning achievements.

Don’s book is one of the better ones for beginners, but should not be your only source. BTW, the youtube videos I point to include the video companion from Don’s book. Ther direct link to Don’s vids for his book is this:

Chapter 1 - Customizing the Shell.mp4 - YouTube&list=PL6D474E721138865A’

Yet, as a new Windows user, it’s important that you look at some beginning Windows / Windows admin vids as well, so, the stuff you use via PoSH will make more sense.

You will also not, Don really does not like the ISE. He lives in the powershell.exe console host and refers to the ISE only when talking to script writing / tool making, graphical user interface development, well that and notepad, for some reason only he knows. 8^} The ISE is my notepad. I’ve even set it as my default vs notepad. When I need to hit the console host, I just shell out to it as needed from within the ISE. Meaning, my code / commands are in the ISE script pane, but if I need to run it in the console host, I just call that from my script code, it runs, closes and returns me back to the ISE, where I continue my work.

You’ll either end up accepting / following how someone else does things, or you will devise your own way to come to grips and use all you are after. I have chosen the latter. Yet, I still read / re-read many of the resources I pointed to as well as follow the authors blogs and more. It’s the only way to stay current and aware.

Again, welcome. Good luck and take care.

postanote - I don’t disagree with anything you are advising. It’s just that I’m at the stage where I’m the proverbial four-year old learning the alphabet. I’m really trying to focus on learning the fundamentals before branching out. With my own personal style of learning in the beginning, I have to focus on mastering the fundamentals. If I bounce around at this point, I will flake out. Personally I’m really big on mastering the basics - the fundamentals. That’s just my style. So at this point I’m just focusing on the Jones-Hicks book and companion videos. Learn what’s in it - back-and-forth\upside-down - precisely because it is stuff that is as basic as it gets. Later on I will look at the broader picture and build upon the fundamentals. I’m older. I have tunnel vision right now. It’s just my focus at this point and not an intent on my part to exclude the vast, rich material that is out there.

The whole thing with the ISE was just to explore it as a lab exercise at the end of Ch. 2 in the Jones-Hicks text. And the text briefly mentioned that PowerShell V2 can be run. So not knowing any better I tried to do it in both the console and in ISE. “Learn by doing.”

Anyway, you answered my question and I am grateful for the clarity you provided.

It is precisely because there is help - actually in this very community, PowerShell.org - that I decided to learn PowerShell.