4

When using PowerShell ISE with Chocolatey to install applications, if I forget the -y switch, it hangs waiting on some sort of "confirmation" that's not popping up anywhere?

I have to Ctrl+Alt+Del to kill PowerShell ISE and Chocolatey and it leaves things in half-way state.

This is what it looks like below:

Screenshot

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • Don't know, but I don't recommend using the ISE as your day-to-day PowerShell console because of potential problems like this. – Bill_Stewart Jan 05 '18 at 20:42
  • Does the folder for the package ever get created? Also, does it work if you start the ISE with -noprofile? Start > Run > powershell_ISE -NoProfile Is any information available in C:\ProgramData\chocolatey\logs relevant to the package you're trying to install? Also, is not having the -y switch a dealbreaker for some reason? – trebleCode Jan 05 '18 at 20:58
  • 1
    PowerShell ISE does not support interactive console applications. There is no question because there is no new line after it. Thus PowerShell does not see it as complete line, does not create `string` object for it and does not render not existing `string` on console. Also there is no way to provide interactive input. – user4003407 Jan 05 '18 at 20:58
  • See also: https://stackoverflow.com/a/8332844/5771128 – Charlie Joynt Jan 05 '18 at 21:34
  • Ah, so Chocolatey is a PowerShell/Console application hybrid it sounds like. So it is calling some console executable wanting an input, even though Chocolatey bills itself as a PowerShell-driven application. Funny, but I guess I see why now. – Alex Kwitny Jan 05 '18 at 22:17

2 Answers2

3

In addition to the comments to the OP above, regarding PowerShell ISE not supporting (most) interactive console applications...

It is worth remembering that the REPL window in PowerShell_ISE.exe is not just some sort of docked PowerShell.exe console. Most of the time the user experience is the same, but this hides a number of differences:

Both these executables are host applications that run a PowerShell runspace (engine). You can even write your own application that "hosts" PowerShell. It is the host application that determines the user experience.

And finally, for the most curious:


I think I wrote this answer more for my own benefit; it's a useful refresher for me as I get asked this by colleagues every now and again...

Charlie Joynt
  • 4,411
  • 1
  • 24
  • 46
  • One thing to note about the differences is that the article is from `2009` (9 years ago), so I'm sure much has changed. One thing I immediately saw was `Start-Transcript` does not work from the ISE, which it does. – Alex Kwitny Jan 05 '18 at 23:31
  • Yeah, there are blogs saying that the aim was to achieve parity between the two applications... but there are others saying that the focus has moved from ISE to VSCode. – Charlie Joynt Jan 05 '18 at 23:37
  • @CharlieJoynt I read the How PowerShell Works article, very interesting read, thanks for sharing – trebleCode Jan 06 '18 at 01:56
  • @CharlieJoynt - VS code is definitely the future, the issue for me (and others) is VSCode doesn't come standard on Windows Server instances. And I'm often working on customers' servers, where they don't like me installing things. – Alex Kwitny Jan 07 '18 at 01:14
0

It's simply because PoSH ISE is not a thing to use for user interactive .exe commands.

If you .exe or whatever expects a response, when in the ISE you have to provide it.

You can easily prove this is not a Chocolatey thing by trying any other .exe that kicks out interactive stuff. For example, just type:

nslookup in the script pane and F8 to run it, or type it in the console pane and hit enter

Either way, the console will just hang, waiting for a interactive response that you cannot provide.

You can still use interactive commands like nslookup in the PoSH ISE, but you have to provide all parameters. For example:

nslookup microsoft.com
nslookup -type=mx microsoft.com
nslookup -q=soa microsoft.com

PS 5.1 even kicks out an error message now.

nslookup

Cannot start "nslookup". Interactive console applications are not supported. To run the application, use the Start-Process cmdlet or use "Start PowerShell.exe" from the File menu.

To view/modify the list of blocked console applications, use $psUnsupportedConsoleApplications, or consult online help. At line:0 char:0

You can easily shell out to the PowerShell console host temporarily this way. Here is a function I have in my profile for such efforts.

Function Start-ConsoleCommand
{
    [CmdletBinding()]

    [Alias('scc')]

    Param  
    ( 
        [string]$ConsoleCommand,
        [switch]$PoSHCore
    )

    If ($PoSHCore)
    {Start-Process pwsh -ArgumentList "-NoExit","-Command  &{ $ConsoleCommand }" -Wait}
    Else
    {Start-Process powershell -ArgumentList "-NoExit","-Command  &{ $ConsoleCommand }" -Wait}

}

So, just type

scc -ConsoleCommand choco install winmerge

It'll pop the console host and stay open until you close it.

Update As per request of - Alex Kwitny

PoSHGet default has only two repositories,

nuget
PSGallery

but you can add your own or another. You use the below cmdlets to make this happen. I have not had to use Chocolatey in a while, but taking a quick look and my archives, the below is what I used

Set up chocolatey repository

Find-Module
Get-Module
Find-Package
Get-Package

Get-PackageProvider
Get-PackageSource
Get-PackageSource -Provider chocolatey
Register-PackageSource -Name chocolatey -Provider Chocolatey -Trusted -Location http://chocolatey.org/api/v2/ -Verbose 

Find-Module
Get-Module
Find-Package
Get-Package
postanote
  • 15,138
  • 2
  • 14
  • 25
  • I am just getting started with Chocolatey, but it just seemed marketed as extremely PowerShell friendly. I just assumed it would have been built to accommodate what I was doing. – Alex Kwitny Jan 07 '18 at 01:12
  • It is, but you only need it if you are on version of PoSH that do not support PowerShellGet. This is part of PoSH v5 by default https://technet.microsoft.com/en-us/library/dn835097.aspx, but you can add it to PoSH v3-4. PowerShellGet is a nuget implementation for PowerShell package management. Package Management Preview for PowerShell 4 & 3 is now available... https://blogs.msdn.microsoft.com/powershell/2015/10/09/package-management-preview-for-powershell-4-3-is-now-available. Noting stops you from using both if there is a need to. I do use both. – postanote Jan 07 '18 at 01:32
  • I wasn't aware of that! So for `PowerShellGet`, does it work with the same chocolatey packages or is there another main repo somewhere? I'll spend some time Googling when I'm at a computer. – Alex Kwitny Jan 08 '18 at 16:29