PowerShellGetv2
PowerShellGetv2 copied to clipboard
Install-Module -Confirm:$false still prompts on untrusted repository
When installing modules from an untrusted repository, I have to specify -Force instead of -Confirm:$false to suppress the prompt. The issue with using -Force is that it forces the reinstall of all the dependent modules.
Steps to reproduce
Install-Module az -AllowClobber -Verbose -AcceptLicense -Confirm:$false -Repository PSGallery
Expected behavior
The module should not prompt for input
Actual behavior
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.0-rc.1
PSEdition Core
GitCommitId 6.2.0-rc.1
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> Get-Module -ListAvailable PowerShellGet,PackageManagement
Directory: C:\Users\kmarquette\Documents\PowerShell\Modules
ModuleType Version Name PSEdition ExportedCommands
---------- ------- ---- --------- ----------------
Script 2.1.2 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-Module, Find…
Directory: C:\program files\powershell\6-preview\Modules
ModuleType Version Name PSEdition ExportedCommands
---------- ------- ---- --------- ----------------
Script 1.3.1 PackageManagement Desk {Find-Package, Get-Package, Get-PackageProvider, G…
Script 2.0.4 PowerShellGet Desk {Find-Command, Find-DSCResource, Find-Module, Find…
> Get-PackageProvider -ListAvailable
Name Version DynamicOptions
---- ------- --------------
NuGet 3.0.0.1 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, …
PowerShellGet 2.1.2.0 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, In…
PowerShellGet 2.0.4.0
@KevinMarquette thanks for reporting this, I see why this can be confusing/unexpected.
The behavior of -Confirm is set to $false by default, but when you specify the parameter it adds an additional check to confirm you want this behavior ex.
And it does not affect the behavior of other checks in place.
Whether the bahavior of -Force in this case is expected is something to discuss since Force generally not tied to Installation Policy, but instead to installation conflicts.
Thank you, That will work for my use case.
Over use of -Force was causing me issues in other places.
In case someone finds this Issue via Google (since it's pretty high up in the results) having the same problem as me trying to install "AzureADPreview" yet still getting a confirmation prompt despite using -Confirm:$false here's an even simpler solution.
Simply do Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted to shortly set PSGallery as trusted, then use Install-Module to install whatever module you want, optionally use Set-PSRepository -Name 'PSGallery' -InstallationPolicy Untrusted to set it back to an Untrusted state for security reasons.
Found this tip here: https://evotec.xyz/powershellgallery-you-are-installing-modules-from-an-untrusted-repository/
In case someone finds this Issue via Google (since it's pretty high up in the results) having the same problem as me trying to install "AzureADPreview" yet still getting a confirmation prompt despite using
-Confirm:$falsehere's an even simpler solution.Simply do
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trustedto shortly set PSGallery as trusted, then useInstall-Moduleto install whatever module you want, optionally useSet-PSRepository -Name 'PSGallery' -InstallationPolicy Untrustedto set it back to an Untrusted state for security reasons.Found this tip here: https://evotec.xyz/powershellgallery-you-are-installing-modules-from-an-untrusted-repository/
I'm running into this same issue trying to Install-Module PSDiscoveryProtocol in a PDQ deployment (which runs Powershell in non-interactive mode) unfortunately Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted doesn't work either - as this command also tries to prompt and fails in the non-interactive session with the same error message...
So far I can't find a way to get this to work.
In case someone finds this Issue via Google (since it's pretty high up in the results) having the same problem as me trying to install "AzureADPreview" yet still getting a confirmation prompt despite using
-Confirm:$falsehere's an even simpler solution. Simply doSet-PSRepository -Name 'PSGallery' -InstallationPolicy Trustedto shortly set PSGallery as trusted, then useInstall-Moduleto install whatever module you want, optionally useSet-PSRepository -Name 'PSGallery' -InstallationPolicy Untrustedto set it back to an Untrusted state for security reasons. Found this tip here: https://evotec.xyz/powershellgallery-you-are-installing-modules-from-an-untrusted-repository/I'm running into this same issue trying to
Install-Module PSDiscoveryProtocolin a PDQ deployment (which runs Powershell in non-interactive mode) unfortunatelySet-PSRepository -Name 'PSGallery' -InstallationPolicy Trusteddoesn't work either - as this command also tries to prompt and fails in the non-interactive session with the same error message...So far I can't find a way to get this to work.
Has anyone found a workaround for this