Skip to content

Update-Module places modules in user path (even when running as Administrator) #9482

Closed

Description

Steps to reproduce

In an elevated powershell core window, choose a module from system path (not user path) and issue Update-Module for it:

PS C:\Users\Leandro> $env:PSModulePath
C:\Users\Leandro\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\windowspowershellcore\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\Leandro> Gci "C:\Program Files\PowerShell\Modules\Az.Automation"


    Directory: C:\Program Files\PowerShell\Modules\Az.Automation

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        17/02/2019    21:25                1.1.0
d-----        08/03/2019    22:55                1.1.1
d-----        06/04/2019    11:24                1.2.0

PS C:\Users\Leandro> update-module AZ.Automation -verbose
VERBOSE: Checking for updates for module 'Az.Automation'.
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2/'; IsTrusted = 'True'; IsRegistered = 'True'.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: Using the specified source names : 'PSGallery'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2/' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az.Automation'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'Az.Automation'.
VERBOSE: Performing the operation "Update-Module" on target "Version '1.2.0' of
module 'Az.Automation', updating to version '1.2.1'".
VERBOSE: The installation scope is specified to be 'CurrentUser'.
VERBOSE: The specified module will be installed in 'C:\Users\Leandro\Documents\PowerShell\Modules'.
VERBOSE: An update for the module 'Az.Automation' was found with version '1.2.1'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'Az.Automation' with version '1.2.1' from the repository 'https://www.powershellgallery.com/api/v2/'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az.Automation'' for ''.
VERBOSE: Package 'Az.Accounts' is already installed.
VERBOSE: Package 'Az.Accounts' is already installed.
VERBOSE: InstallPackage' - name='Az.Automation', version='1.2.1',destination='C:\Users\Leandro\AppData\Local\Temp\1176232375'
VERBOSE: DownloadPackage' - name='Az.Automation', version='1.2.1',destination='C:\Users\Leandro\AppData\Local\Temp\1176232375\Az.Automation.1.2.1\Az.Automation.1.2.1.nupkg', uri='https://www.powershellgallery.com/api/v2/package/Az.Automation/1.2.1'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/Az.Automation/1.2.1'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/Az.Automation/1.2.1'.
VERBOSE: Completed downloading 'Az.Automation'.
VERBOSE: InstallPackageLocal' - name='Az.Automation', version='1.2.1',destination='C:\Users\Leandro\AppData\Local\Temp\1176232375'
VERBOSE: Validating the 'Az.Automation' module contents under 'C:\Users\Leandro\AppData\Local\Temp\1176232375\Az.Automation.1.2.1' path.
VERBOSE: Test-ModuleManifest successfully validated the module manifest file 'C:\Users\Leandro\AppData\Local\Temp\1176232375\Az.Automation.1.2.1'.
VERBOSE: Validating the authenticode signature and publisher of the catalog file or module manifest file of the module 'Az.Automation'.
VERBOSE: Catalog file 'Az.Automation.cat' is not found in the contents of the module 'Az.Automation' being installed.
VERBOSE: For publisher validation, current module 'Az.Automation' with version '1.2.1' with publisher name '' from root certificate authority ''. Is this module signed by Microsoft: 'False'.
VERBOSE: For publisher validation, using the previously-installed module 'Az.Automation' with version '1.2.0' under 'C:\Program Files\PowerShell\Modules\Az.Automation\1.2.0' with publisher name '' from root certificate authority ''. Is this module signed by Microsoft: 'False'.
VERBOSE: Checking for possible command collisions for the module 'Az.Automation' commands.
VERBOSE: Module 'Az.Automation' was installed successfully to path 'C:\Users\Leandro\Documents\PowerShell\Modules\Az.Automation\1.2.1'.
PS C:\Users\Leandro> Gci "C:\Program Files\PowerShell\Modules\Az.Automation"


    Directory: C:\Program Files\PowerShell\Modules\Az.Automation

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        17/02/2019    21:25                1.1.0
d-----        08/03/2019    22:55                1.1.1
d-----        06/04/2019    11:24                1.2.0

PS C:\Users\Leandro> gci "C:\Users\Leandro\Documents\PowerShell\Modules\Az.Automation"


    Directory: C:\Users\Leandro\Documents\PowerShell\Modules\Az.Automation

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        26/04/2019    22:30                1.2.1

PS C:\Users\Leandro>

Expected behavior

Module should be placed in the system path (in my example "C:\Program Files\PowerShell\Modules\Az.Automation")

Actual behavior

Module was placed in the user path (in my example "C:\Users\Leandro\Documents\PowerShell\Modules\Az.Automation"

Environment data

PS C:\Users\Leandro> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Apr 27, 2019
  2. lwajswaj commented on Apr 27, 2019

    @lwajswaj
    Author

    These modules were installed using -Scope AllUsers.

    Update-Module doesn't expose an -Scope parameter:

    PS C:\Users\Leandro> Get-Help Update-Module
    
    NAME
        Update-Module
    
    SYNTAX
        Update-Module [[-Name] <string[]>] [-RequiredVersion <string>]
        [-MaximumVersion <string>] [-Credential <pscredential>] [-Proxy <uri>]
        [-ProxyCredential <pscredential>] [-Force] [-AllowPrerelease]
        [-AcceptLicense] [-WhatIf] [-Confirm] [<CommonParameters>]
    
    
    ALIASES
        upmo
    
    
    REMARKS
        Get-Help cannot find the Help files for this cmdlet on this computer. It
        is displaying only partial help.
            -- To download and install Help files for the module that includes
        this cmdlet, use Update-Help.
            -- To view the Help topic for this cmdlet online, type: "Get-Help
        Update-Module -Online" or
               go to https://go.microsoft.com/fwlink/?LinkID=398576.
  3. vexx32 commented on Apr 27, 2019

    @vexx32
    Collaborator

    chuanjiao it seems the goal here is to have update-module correctly work for modules in the system path. It doesn't look like Leandro Wajswajn Pereyra (@lwajswaj) wants the module to be in the user-specific path.

  4. lwajswaj commented on Apr 27, 2019

    @lwajswaj
    Author
  5. fMichaleczek commented on Apr 28, 2019

    @fMichaleczek
    Contributor

    Leandro Wajswajn Pereyra (@lwajswaj) You should move your issue to PowerShellGet repository instead.

    The behavior is located here : Get-InstallationScope.ps1#L2

    Determine scope. We prefer CurrentUser scope even if the older module is installed for AllUsers, unless:
    old module is installed for all users, we are elevated, AND using Windows PowerShell
    This is to mirror newer behavior of Install-Module.

  6. lwajswaj commented on Apr 28, 2019

    @lwajswaj
    Author

    OK, the issue with this preference is it doesn't play well when module is required at system level such as modules needed to be executed by SYSTEM or a Service Account (like the case of an Azure DevOps hosted agent).

  7. added
    Resolution-External
    on Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-External

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions