macos image: PowerShell: Install-Module does not work

Florian Feldhaus's Avatar

Florian Feldhaus

03 Aug, 2020 07:38 PM

The macos image is really great, but unfortunately it does not allow to run Install-Module in PowerShell which is very important to install the Pester testing framework. Doing so results in the following error:

Install-Module Pester -Scope CurrentUser -Force -SkipPublisherCheck -MinimumVersion 4.4.4 -MaximumVersion 4.999
Install-Package: /usr/local/microsoft/powershell/7/Modules/PowerShellGet/PSModule.psm1:9709
Line |
9709 |  … talledPackages = PackageManagement\Install-Package @PSBoundParameters
     |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Administrator rights are required to install or update. Log on to the computer with an account that has Administrator rights, and then try again, or install by adding "-Scope CurrentUser" to your command. You can also try
     | running the Windows PowerShell session with elevated rights (Run as Administrator).

The problem seems to be that the PSGallery repository, which is available by default in PowerShell has InstallationPolicy set to untrusted:


Get-PSRepository
Name                      : PSGallery
SourceLocation            : https://www.powershellgallery.com/api/v2
Trusted                   : False
Registered                : True
InstallationPolicy        : Untrusted
PackageManagementProvider : NuGet
PublishLocation           : https://www.powershellgallery.com/api/v2/package/
ScriptSourceLocation      : https://www.powershellgallery.com/api/v2/items/psscript
ScriptPublishLocation     : https://www.powershellgallery.com/api/v2/package/
ProviderOptions           : {}

Is it possible to change the InstallationPolicy to trusted in the macos image like it is with all other images? If not, why is it not possible?

  1. Support Staff 1 Posted by Feodor Fitsner on 04 Aug, 2020 12:46 AM

    Feodor Fitsner's Avatar

    Hi Florian,

    Do you have a repro appveyor.yml for this issue?

  2. 2 Posted by Florian Feldhau... on 04 Aug, 2020 10:28 AM

    Florian Feldhaus's Avatar

    Sure, here is the repo:
    https://github.com/ffeldhaus/appveyor

    Here is the test with 4 images:
    https://ci.appveyor.com/project/ffeldhaus/appveyor

    Only the macos image has the problem:
    https://ci.appveyor.com/project/ffeldhaus/appveyor/build/job/m0ih17...

    BTW: I was very surprised to see that Visual Studio 2019 shows PowerShell 5.1:
    https://ci.appveyor.com/project/ffeldhaus/appveyor/build/job/g1q8nl...

    The "Software pre-installed on Windows build VMs" list only mentions PowerShell 7:
    https://www.appveyor.com/docs/windows-images-software/

  3. 3 Posted by jakewmorrison on 28 Aug, 2020 03:57 AM

    jakewmorrison's Avatar

    Seeing a similar issue on my project.

    Build: https://ci.appveyor.com/project/techthoughts2/poshgram

    Repo: https://github.com/techthoughts2/PoshGram/tree/Enhancements

    This was not occurring when the MacOS was running
    PSVersion 6.2.4

    But now it is running:
    PSVersion 7.0.1

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac