PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available."

Open matt-richardson opened this issue 8 years ago • 13 comments

If spent the last few days banging my head against the wall, trying to get Publish-Module to work from under a TeamCity build. I've installed WMF5, downloaded nuget to C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe, but still getting an error:

Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available."

I'm using version 1.0.0.1 of PowershellGet and PackageManagement.

[11:37:32]	##Get-Module PowershellGet
[11:37:32]	
[11:37:32]	ModuleType Version    Name                                ExportedCommands                                             
[11:37:32]	---------- -------    ----                                ----------------                                             
[11:37:32]	Script     1.0.0.1    PowerShellGet                       {Find-DscResource, Find-Module, Find-Script, Get-Installed...
[11:37:32]	###Get-Module PackageManagement
[11:37:32]	Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
[11:37:32]	###Get-Command -Name Publish-Module -Module PowerShellGet -Syntax
[11:37:32]	
[11:37:32]	Publish-Module -Name <string> [-RequiredVersion <version>] [-NuGetApiKey <string>] [-Repository <string>] 
[11:37:32]	[-FormatVersion <version>] [-ReleaseNotes <string[]>] [-Tags <string[]>] [-LicenseUri <uri>] [-IconUri <uri>] 
[11:37:32]	[-ProjectUri <uri>] [-WhatIf] [-Confirm] [<CommonParameters>]
[11:37:32]	
[11:37:32]	Publish-Module -Path <string> [-NuGetApiKey <string>] [-Repository <string>] [-FormatVersion <version>] [-ReleaseNotes 
[11:37:32]	<string[]>] [-Tags <string[]>] [-LicenseUri <uri>] [-IconUri <uri>] [-ProjectUri <uri>] [-WhatIf] [-Confirm] 
[11:37:32]	[<CommonParameters>]

Oddly enough, on my local machine, running the same commands gives me version 1.0.0.1 of both packages, but there is an additional -Force parameter available. No idea why there are different arguments for the same versions. My local machine has PS 5.1, but the build agent has 5.0

Somehow, I managed to get one successful publish out of it, but it didn't work on other build agents. No idea why.

Expected Behavior

I expect it to publish the package. Or, failing that, tell me whats wrong and how to fix it.

If running in non-interactive mode, and nuget is not available, it should fail with a message along the lines of "The nuget package provider is not available. Please run Install-PackageProvider nuget.".

Once we've figured out why -force is available on some machines and not on others, the message could possibly be something like "The nuget package provider is not available. Please re-run the command with the -Force parameter to install the provider automatically, or install it separately via Install-PackageProvider nuget.".

Current Behavior

It fails with the exception Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available."

Possible Solution

Steps to Reproduce (for bugs)

try 
{
    write-host "###`$PSVersionTable"
    $PSVersionTable | Write-Output
    write-host "###Get-Module"
    Get-Module
    write-host "###Get-Module -ListAvailable PowerShellGet,PackageManagement"
    Get-Module -ListAvailable PowerShellGet,PackageManagement
    write-host "###Get-PackageProvider"
    Get-PackageProvider
    write-host "###Get-PackageProvider -ListAvailable"
    Get-PackageProvider -ListAvailable


    $content = (Get-Content OctopusDSC/OctopusDSC.psd1)
    $content = $content -replace "ModuleVersion = '[0-9\.]+'", "ModuleVersion = '%build.number%'"
    Set-Content OctopusDSC/OctopusDSC.psd1 $content

    Write-output "###Get-Content OctopusDSC/OctopusDSC.psd1"
    $content

    Write-output "###Import Modules"
    Import-Module "C:\Program Files\WindowsPowerShell\Modules\PackageManagement"
    Import-Module "C:\Program Files\WindowsPowerShell\Modules\PowerShellGet"

    Write-output "###Ensuring nuget.exe is available"
    If (-not (Test-Path "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe")) {
        Write-output "Downloading latest nuget to C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
        if (-not (Test-Path "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet")) {
            New-Item -type Directory "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet" | Out-Null
        }
        Invoke-WebRequest -Uri "http://go.microsoft.com/fwlink/?LinkID=690216&clcid=0x409" -OutFile "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
    }

    Write-output "###Get-Module PowershellGet"
    Get-Module PowershellGet
    Write-output "###Get-Module PackageManagement"
    Get-Module PackageManagement

    Write-output "###Get-Command -Name Publish-Module -Module PowerShellGet -Syntax"
    Get-Command -Name Publish-Module -Module PowerShellGet -Syntax

    Write-output "###Publish-Module -Path 'OctopusDSC'"
    Publish-Module -Path "OctopusDSC" -NuGetApiKey "%PSGallery.ApiKey%" -verbose
}
catch
{
    write-host $_
    exit 1
}

Context

Your Environment

[17:06:24]	###Get-Module
[17:06:24]	
[17:06:24]	Name              : Microsoft.PowerShell.Utility
[17:06:24]	Path              : C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShel
[17:06:24]	                    l.Utility.psd1
[17:06:24]	Description       : 
[17:06:24]	Guid              : 1da87e53-152b-403e-98dc-74d7b4d63d59
[17:06:24]	Version           : 3.1.0.0
[17:06:24]	ModuleBase        : C:\Windows\SysWOW64\WindowsPowerShell\v1.0
[17:06:24]	ModuleType        : Manifest
[17:06:24]	PrivateData       : 
[17:06:24]	AccessMode        : ReadWrite
[17:06:24]	ExportedAliases   : {[CFS, CFS], [fhx, fhx]}
[17:06:24]	ExportedCmdlets   : {[Add-Member, Add-Member], [Add-Type, Add-Type], [Clear-Variable, Clear-Variable], 
[17:06:24]	                    [Compare-Object, Compare-Object]...}
[17:06:24]	ExportedFunctions : {[ConvertFrom-SddlString, ConvertFrom-SddlString], [Format-Hex, Format-Hex], [Get-FileHash, 
[17:06:24]	                    Get-FileHash], [Import-PowerShellDataFile, Import-PowerShellDataFile]...}
[17:06:24]	ExportedVariables : {}
[17:06:24]	NestedModules     : {Microsoft.PowerShell.Commands.Utility.dll, Microsoft.PowerShell.Utility}
[17:06:24]	
[17:06:24]	###Get-Module -ListAvailable PowerShellGet,PackageManagement
[17:06:25]	
[17:06:25]	Name              : PackageManagement
[17:06:25]	Path              : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\PackageManagement.psd1
[17:06:25]	Description       : 
[17:06:25]	Guid              : 4ae9fd46-338a-459c-8186-07f910774cb8
[17:06:25]	Version           : 1.0.0.1
[17:06:25]	ModuleBase        : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1
[17:06:25]	ModuleType        : Binary
[17:06:25]	PrivateData       : 
[17:06:25]	AccessMode        : ReadWrite
[17:06:25]	ExportedAliases   : {}
[17:06:25]	ExportedCmdlets   : {[Find-Package, Find-Package], [Get-Package, Get-Package], [Get-PackageProvider, 
[17:06:25]	                    Get-PackageProvider], [Get-PackageSource, Get-PackageSource]...}
[17:06:25]	ExportedFunctions : {}
[17:06:25]	ExportedVariables : {}
[17:06:25]	NestedModules     : {}
[17:06:25]	
[17:06:25]	
[17:06:25]	Name              : PowerShellGet
[17:06:25]	Path              : C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PowerShellGet.psd1
[17:06:25]	Description       : 
[17:06:25]	Guid              : 1d73a601-4a6c-43c5-ba3f-619b18bbb404
[17:06:25]	Version           : 1.0.0.1
[17:06:25]	ModuleBase        : C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1
[17:06:25]	ModuleType        : Script
[17:06:25]	PrivateData       : {SupportedPowerShellGetFormatVersions, PackageManagementProviders}
[17:06:25]	AccessMode        : ReadWrite
[17:06:25]	ExportedAliases   : {[inmo, inmo], [fimo, fimo], [upmo, upmo], [pumo, pumo]}
[17:06:25]	ExportedCmdlets   : {}
[17:06:25]	ExportedFunctions : {[Install-Module, Install-Module], [Find-Module, Find-Module], [Save-Module, Save-Module], 
[17:06:25]	                    [Update-Module, Update-Module]...}
[17:06:25]	ExportedVariables : {}
[17:06:25]	NestedModules     : {}
[17:06:25]	
[17:06:25]	###Get-PackageProvider
[17:06:46]	
[17:06:46]	Name                    : msi
[17:06:46]	ProviderName            : msi
[17:06:46]	Features                : {[file-extensions, System.Collections.Generic.List`1[System.String]], [magic-signatures, 
[17:06:46]	                          System.Collections.Generic.List`1[System.String]]}
[17:06:46]	Version                 : 3.0.0.0
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\Microsoft.PackageM
[17:06:46]	                          anagement.MsiProvider.dll
[17:06:46]	SupportedFileExtensions : {msi, msp}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {AdditionalArguments}
[17:06:46]	
[17:06:46]	
[17:06:46]	Name                    : msu
[17:06:46]	ProviderName            : msu
[17:06:46]	Features                : {[file-extensions, System.Collections.Generic.List`1[System.String]], [magic-signatures, 
[17:06:46]	                          System.Collections.Generic.List`1[System.String]]}
[17:06:46]	Version                 : 3.0.0.0
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\Microsoft.PackageM
[17:06:46]	                          anagement.MsuProvider.dll
[17:06:46]	SupportedFileExtensions : {msu}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {}
[17:06:46]	
[17:06:46]	
[17:06:46]	Name                    : PowerShellGet
[17:06:46]	ProviderName            : PowerShellGet
[17:06:46]	Features                : {[supports-powershell-modules, System.Collections.Generic.List`1[System.String]]}
[17:06:46]	Version                 : 1.0.0.1
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1
[17:06:46]	SupportedFileExtensions : {}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {PackageManagementProvider, Type, Scope, InstallUpdate...}
[17:06:46]	
[17:06:46]	
[17:06:46]	Name                    : Programs
[17:06:46]	ProviderName            : Programs
[17:06:46]	Features                : {}
[17:06:46]	Version                 : 3.0.0.0
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\Microsoft.PackageM
[17:06:46]	                          anagement.CoreProviders.dll
[17:06:46]	SupportedFileExtensions : {}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {IncludeWindowsInstaller, IncludeSystemComponent}
[17:06:46]	
[17:06:46]	###Get-PackageProvider -ListAvailable
[17:06:46]	
[17:06:46]	Name                    : msi
[17:06:46]	ProviderName            : msi
[17:06:46]	Features                : {[file-extensions, System.Collections.Generic.List`1[System.String]], [magic-signatures, 
[17:06:46]	                          System.Collections.Generic.List`1[System.String]]}
[17:06:46]	Version                 : 3.0.0.0
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\Microsoft.PackageM
[17:06:46]	                          anagement.MsiProvider.dll
[17:06:46]	SupportedFileExtensions : {msi, msp}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {AdditionalArguments}
[17:06:46]	
[17:06:46]	
[17:06:46]	Name                    : msu
[17:06:46]	ProviderName            : msu
[17:06:46]	Features                : {[file-extensions, System.Collections.Generic.List`1[System.String]], [magic-signatures, 
[17:06:46]	                          System.Collections.Generic.List`1[System.String]]}
[17:06:46]	Version                 : 3.0.0.0
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\Microsoft.PackageM
[17:06:46]	                          anagement.MsuProvider.dll
[17:06:46]	SupportedFileExtensions : {msu}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {}
[17:06:46]	
[17:06:46]	
[17:06:46]	Name                    : PowerShellGet
[17:06:46]	ProviderName            : PowerShellGet
[17:06:46]	Features                : {[supports-powershell-modules, System.Collections.Generic.List`1[System.String]]}
[17:06:46]	Version                 : 1.0.0.1
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1
[17:06:46]	SupportedFileExtensions : {}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {PackageManagementProvider, Type, Scope, InstallUpdate...}
[17:06:46]	
[17:06:46]	
[17:06:46]	Name                    : Programs
[17:06:46]	ProviderName            : Programs
[17:06:46]	Features                : {}
[17:06:46]	Version                 : 3.0.0.0
[17:06:46]	ProviderPath            : C:\Program Files (x86)\WindowsPowerShell\Modules\PackageManagement\1.0.0.1\Microsoft.PackageM
[17:06:46]	                          anagement.CoreProviders.dll
[17:06:46]	SupportedFileExtensions : {}
[17:06:46]	SupportedUriSchemes     : {}
[17:06:46]	DynamicOptions          : {IncludeWindowsInstaller, IncludeSystemComponent}

matt-richardson avatar Dec 20 '16 06:12 matt-richardson

Turns out adding a Install-PackageProvider nuget -force makes it work.

Keeping it open as it the exception message should be improved for this scenario.

matt-richardson avatar Dec 20 '16 06:12 matt-richardson

@matt-richardson The above mentioned error message is returned by the PowerShell runtime. This is an expected error in non-interactive mode when you don't have the pre-requisites installed like NuGet provider and/or NuGet.exe. Please update the Expected Behavior with expected message you would like to get in this scenario.

bmanikm avatar Dec 20 '16 19:12 bmanikm

Can you tell me why -force is available locally, but not on the build agent?

matt-richardson avatar Dec 20 '16 21:12 matt-richardson

I've updated the Expected Behaviour, but not sure its a great idea to get someone who knows very little about how this all works together to design the error messages.

matt-richardson avatar Dec 20 '16 21:12 matt-richardson

Thanks @matt-Richardson ! Your build agent might be having the PowerShellGet module from previous releases. Please work with your 'Team City' team to have the latest version of PowerShellGet module from the PowerShell Gallery. Get the latest version from PowerShell Gallery

bmanikm avatar Dec 20 '16 23:12 bmanikm

Both my local packages and the ones on the build agents have version 1.0.0.1. One has the -force parameter, and one doesn't. Are there multiple different versions out there with the same version number?

matt-richardson avatar Dec 21 '16 19:12 matt-richardson

Inbox version of PowerShellGet module is 1.0.0.1 in WMF 5.0/5.1, Windows 10 and Windows Server 2016 releases. Version of inbox release is not changed to ensure that Windows Servicing/Updates work fine. In future, we would like resolve this versioning issue for inbox release.

bmanikm avatar Dec 21 '16 20:12 bmanikm

@matt-richardson - There were alot of changes made between the initial 1.0.0.1 version of PowerShellGet that was released in the Windows 10 RTM (& WMF 5) and the 1.0.0.1 version of PowerShellGet that was in the Anniversary Edition of Windows 10 (which has WMF 5.1). One of the many changes was to include the -Force parameter.

Even though I noticed this and brought it up via the MVP distribution list and had the conversation about why this was unacceptable it still happened.

Also From the screenshot above It looks like you've been running this in the x86 PowerShell shell - Can you re-run from the x64 shell at all?

If not then I have a small script that I can dig out for you that you could use to will download and install a later Version of PowerShellGet (or any other module) from the PowerShell Gallery that doesn't use the PowerShellGet Module at all.

Let me know if that would be of any help at all and I'll dig it out for you.

kilasuit avatar Dec 22 '16 10:12 kilasuit

Thanks for the detailed response, @kilasuit. Shame that it happened that way. I've managed to get it all working now, so dont need that script - thanks.

matt-richardson avatar Jan 01 '17 19:01 matt-richardson

Any particular reason this has been closed? I hit it again the other day.

matt-richardson avatar Oct 10 '18 22:10 matt-richardson

Sorry, just trying to organize some of the older issues should be re-opened now...

SydneyhSmith avatar Oct 10 '18 23:10 SydneyhSmith

@matt-richardson are you still using version 1.0.0.1 of PowershellGet and PackageManagement?

alerickson avatar Nov 05 '18 22:11 alerickson

Do not forget to perform Install-PackageManager "NuGet" on the correct version of PowerShell (x86 vs x64)! Just took me more than an hour to find out I installed it on the wrong instance.

drauch avatar Apr 02 '19 11:04 drauch