Skip to content

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

@lwajswaj

Description

@lwajswaj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-ExternalThe issue is caused by external component(s).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions