PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Installing PowerShell modules in the CurrentUser scope of the System user silently fails.

Open VertigoRay opened this issue 5 years ago • 4 comments

Steps to reproduce

Login to the System user however you want ...

PS C:\> whoami
nt authority\system
PS C:\> $env:PSModulePath.Split(';')[0]
\PowerShell\Modules
PS C:\> Install-Module QuserObject -Scope CurrentUser -Force
PS C:\> Get-Module QuserObject -ListAvailable

Expected behavior

PS C:\> whoami
nt authority\system
PS C:\> $env:PSModulePath.Split(';')[0]
C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules
PS C:\> Install-Module QuserObject -Scope CurrentUser -Force
PS C:\> Get-Module QuserObject -ListAvailable

    Directory: C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.2.30     QuserObject

Actual behavior

Does not install the module anywhere that I can tell. Here's a transcript:

**********************
PowerShell transcript start
Start time: 20201112101351
Username: UNT\CAS-TEST-10U01$
RunAs User: UNT\CAS-TEST-10U01$
Configuration Name: 
Machine: CAS-TEST-10U01 (Microsoft Windows NT 10.0.19041.0)
Host Application: C:\Program Files\PowerShell\7\pwsh.dll
Process ID: 7628
PSVersion: 7.1.0
PSEdition: Core
GitCommitId: 7.1.0
OS: Microsoft Windows 10.0.19041
Platform: Win32NT
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0, 6.1.0, 6.2.0, 7.0.0, 7.1.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
WSManStackVersion: 3.0
**********************
Transcript started, output file is C:\pwsh.log
**********************
Command start time: 20201112101402
**********************
PS C:\> whoami

**********************
Command start time: 20201112101415
**********************
PS C:\> [System.Environment]::GetFolderPath('MyDocuments')

**********************
Command start time: 20201112101427
**********************
PS C:\> $env:PSModulePath.Split(';')[0]
PowerShell\Modules
**********************
Command start time: 20201112101438
**********************
PS C:\> Install-Module QuserObject -Scope CurrentUser -Force
**********************
Command start time: 20201112101453
**********************
PS C:\> Get-Module QuserObject -ListAvailable
**********************
Command start time: 20201112101501
**********************
PS C:\> Install-Module QuserObject -Scope CurrentUser -Force -Verbose -Debug
DEBUG: 00:00:00.0000004 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0000446 Debug: True
DEBUG: 00:00:00.0000554 Force: True
DEBUG: 00:00:00.0000656 Name: QuserObject
DEBUG: 00:00:00.0000760 Verbose: True
DEBUG: 00:00:00.0015992 INVOKING PowerShell Fn Get-DynamicOptions with args Provider that has length 1
DEBUG: 00:00:00.0022434 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0062378 Done calling powershell «Get-DynamicOptions» «PSModule»
DEBUG: 00:00:00.0097398 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0097704 Debug: True
DEBUG: 00:00:00.0097809 Force: True
DEBUG: 00:00:00.0097911 Name: QuserObject
DEBUG: 00:00:00.0098014 Verbose: True
DEBUG: 00:00:00.0127181 INVOKING PowerShell Fn Get-DynamicOptions with args Source that has length 1
DEBUG: 00:00:00.0135386 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0149707 Done calling powershell «Get-DynamicOptions» «PSModule»
DEBUG: 00:00:00.0176057 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0176368 Debug: True
DEBUG: 00:00:00.0176475 Force: True
DEBUG: 00:00:00.0176579 Name: QuserObject
DEBUG: 00:00:00.0176683 Verbose: True
DEBUG: 00:00:00.0181865 INVOKING PowerShell Fn Get-DynamicOptions with args Package that has length 1
DEBUG: 00:00:00.0186363 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0214575 Done calling powershell «Get-DynamicOptions» «PSModule»
DEBUG: 00:00:00.0241414 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0241730 Debug: True
DEBUG: 00:00:00.0241839 Force: True
DEBUG: 00:00:00.0241941 Name: QuserObject
DEBUG: 00:00:00.0242044 Verbose: True
DEBUG: 00:00:00.0396841 INVOKING PowerShell Fn Get-DynamicOptions with args Install that has length 1
DEBUG: 00:00:00.0455853 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0494100 Done calling powershell «Get-DynamicOptions» «PSModule»
DEBUG: 00:00:00.1476645 Calling SearchForPackages. Name='QuserObject'
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
DEBUG: 00:00:00.1486529 PackageProvider::FindPackage with name QuserObject
DEBUG: 00:00:00.1513893 Calling SearchForPackages After Select 1
DEBUG: 00:00:00.1757261 Calling New() : MethodName = 'FindPackage'
DEBUG: 00:00:00.1772587 Scope: CurrentUser
DEBUG: 00:00:00.1780571 Verbose: True
DEBUG: 00:00:00.1787760 Type: Module
DEBUG: 00:00:00.1794852 MessageResolver: Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:00.1802341 Debug: True
DEBUG: 00:00:00.1809703 Name: QuserObject
DEBUG: 00:00:00.1816718 ProviderName: PowerShellGet
DEBUG: 00:00:00.1823868 Force: True
DEBUG: 00:00:00.1834876 INVOKING PowerShell Fn Find-Package with args System.String[], , ,  that has length 4
DEBUG: 00:00:00.1892882 In PowerShellGet Provider - 'Find-Package'.
DEBUG: 00:00:00.1907641 OPTION: Scope => CurrentUser
DEBUG: 00:00:00.1917230 OPTION: Verbose => True
DEBUG: 00:00:00.1926164 OPTION: Type => Module
DEBUG: 00:00:00.1935143 OPTION: MessageResolver => Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:00.1944879 OPTION: Debug => True
DEBUG: 00:00:00.1952005 OPTION: Name => QuserObject
DEBUG: 00:00:00.1958851 OPTION: ProviderName => PowerShellGet
DEBUG: 00:00:00.1966108 OPTION: Force => True
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://powershellgallery.cas.unt.edu/' and PackageManagementProvider is 'NuGet'.
DEBUG: 00:00:00.2405717 PackageProvider::FindPackage with name QuserObject
DEBUG: 00:00:00.2437689 Calling 'NuGet'::'FindPackage' - name='QuserObject', requiredVersion='',minimumVersion='', maximumVersion='''.
DEBUG: 00:00:00.2447674 Iterating 'QuserObject'.
DEBUG: 00:00:00.2458241 There are '0' registered sources in 'NuGet' provider.
DEBUG: 00:00:00.2464542 Source 'https://powershellgallery.cas.unt.edu/' is not one of the registered sources in 'NuGet' provider.
DEBUG: 00:00:00.2474178 Source 'https://powershellgallery.cas.unt.edu/' is validated.
DEBUG: 00:00:00.2536780 Calling 'NuGetRequest'::'GetPackageById', 'QuserObject'.
DEBUG: 00:00:00.2548608 Calling 'NuGetPackageRepository'::'FindPackagesById', 'QuserObject'.
DEBUG: 00:00:00.2558979 Calling 'NuGetPackageFeed2'::'FindPackage', 'QuserObject'.
DEBUG: 00:00:00.2569081 Calling 'NuGetClient'::'FindPackage'.
VERBOSE: Searching repository 'https://powershellgallery.cas.unt.edu/FindPackagesById()?id='QuserObject'' for ''.
DEBUG: 00:00:00.2587578 Downloading 'https://powershellgallery.cas.unt.edu/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:00.2703584 Completed downloading 'https://powershellgallery.cas.unt.edu/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:00.2717352 '0' packages received in the last request.
DEBUG: 00:00:00.2731037 System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.PackageManagement.NuGetProvider.NuGetRequest.GetPackageById(PackageSource source, String name, NuGetRequest request, String requiredVersion, String minimumVersion, String maximumVersion, Boolean minInclusive, Boolean maxInclusive, Boolean isDependency)
VERBOSE: Total package yield:'0' for the specified package 'QuserObject'.
DEBUG: 00:00:00.2751953 Completed iterating for 'QuserObject'.
DEBUG: 00:00:00.2760451 Calling 'NuGetRequest'::'FindRegisteredSource', 'https://powershellgallery.cas.unt.edu/'.
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'.
DEBUG: 00:00:00.2891648 PackageProvider::FindPackage with name QuserObject
DEBUG: 00:00:00.3042837 Calling 'NuGet'::'FindPackage' - name='QuserObject', requiredVersion='',minimumVersion='', maximumVersion='''.
DEBUG: 00:00:00.3054717 Iterating 'QuserObject'.
DEBUG: 00:00:00.3066773 There are '0' registered sources in 'NuGet' provider.
DEBUG: 00:00:00.3077243 Source 'https://www.powershellgallery.com/api/v2' is not one of the registered sources in 'NuGet' provider.
DEBUG: 00:00:00.3172548 Source 'https://www.powershellgallery.com/api/v2' is validated.
DEBUG: 00:00:00.3185149 Calling 'NuGetRequest'::'GetPackageById', 'QuserObject'.
DEBUG: 00:00:00.3194553 Calling 'NuGetPackageRepository'::'FindPackagesById', 'QuserObject'.
DEBUG: 00:00:00.3203263 Calling 'NuGetPackageFeed2'::'FindPackage', 'QuserObject'.
DEBUG: 00:00:00.3211847 Calling 'NuGetClient'::'FindPackage'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'' for ''.
DEBUG: 00:00:00.3229132 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:00.4790297 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:00.4860124 '22' packages received in the last request.
DEBUG: 00:00:00.4872222 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:00.5409382 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:00.5516995 '22' packages received in the last request.
VERBOSE: Total package yield:'1' for the specified package 'QuserObject'.
DEBUG: 00:00:00.5553292 Completed iterating for 'QuserObject'.
DEBUG: 00:00:00.5609674 Done calling powershell «Find-Package» «PSModule»
DEBUG: 00:00:00.5660015 Calling New() : MethodName = 'GetInstalledPackages'
DEBUG: 00:00:00.5667802 Scope: CurrentUser
DEBUG: 00:00:00.5674743 Verbose: True
DEBUG: 00:00:00.5682222 Type: Module
DEBUG: 00:00:00.5695759 MessageResolver: Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:00.5705996 Debug: True
DEBUG: 00:00:00.5714096 Name: QuserObject
DEBUG: 00:00:00.5721819 ProviderName: PowerShellGet
DEBUG: 00:00:00.5729561 Force: True
DEBUG: 00:00:00.5744829 INVOKING PowerShell Fn Get-InstalledPackage with args QuserObject, 0.2.30, ,  that has length 4
DEBUG: 00:00:00.5762362 In PowerShellGet Provider - 'Get-InstalledPackage'.
DEBUG: 00:00:00.5771099 OPTION: Scope => CurrentUser
DEBUG: 00:00:00.5779022 OPTION: Verbose => True
DEBUG: 00:00:00.5786784 OPTION: Type => Module
DEBUG: 00:00:00.5794784 OPTION: MessageResolver => Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:00.5802693 OPTION: Debug => True
DEBUG: 00:00:00.5810458 OPTION: Name => QuserObject
DEBUG: 00:00:00.5818175 OPTION: ProviderName => PowerShellGet
DEBUG: 00:00:00.5825903 OPTION: Force => True
DEBUG: 00:00:01.0721231 Done calling powershell «Get-InstalledPackage» «PSModule»
Confirm
Are you sure you want to perform this action?
Performing the operation "Install-Module" on target "Version '0.2.30' of module 'QuserObject'".
&Yes  Yes to &All  &No  No to A&ll  &Suspend
A
DEBUG: 00:00:07.1434374 Calling New() : MethodName = 'InstallPackage'
DEBUG: 00:00:07.1445865 Scope: CurrentUser
DEBUG: 00:00:07.1453689 Verbose: True
DEBUG: 00:00:07.1460923 Type: Module
DEBUG: 00:00:07.1468380 MessageResolver: Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:07.1475084 Debug: True
DEBUG: 00:00:07.1480968 Name: QuserObject
DEBUG: 00:00:07.1486887 ProviderName: PowerShellGet
DEBUG: 00:00:07.1492686 Force: True
DEBUG: 00:00:07.1504551 INVOKING PowerShell Fn Install-Package with args NuGet|QuserObject|0.2.30|https://www.powershellgallery.com/api/v2|Module that has length 1
DEBUG: 00:00:07.1556549 In PowerShellGet Provider - 'Install-Package'.
DEBUG: 00:00:07.1568271 In PowerShellGet Provider - 'Install-PackageUtility'.
DEBUG: 00:00:07.1577787 The FastPackageReference is 'NuGet|QuserObject|0.2.30|https://www.powershellgallery.com/api/v2|Module'.
DEBUG: 00:00:07.1590745 OPTION: Scope => CurrentUser
DEBUG: 00:00:07.1599620 OPTION: Verbose => True
DEBUG: 00:00:07.1608884 OPTION: Type => Module
DEBUG: 00:00:07.1616006 OPTION: MessageResolver => Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:07.1623087 OPTION: Debug => True
DEBUG: 00:00:07.1629706 OPTION: Name => QuserObject
DEBUG: 00:00:07.1636880 OPTION: ProviderName => PowerShellGet
DEBUG: 00:00:07.1643534 OPTION: Force => True
VERBOSE: The installation scope is specified to be 'CurrentUser'.
VERBOSE: The specified module will be installed in 'C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules'.
DEBUG: 00:00:07.1668767 ArtifactType is Module
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'QuserObject' with version '0.2.30' from the repository 'https://www.powershellgallery.com/api/v2'.
DEBUG: 00:00:07.2274650 Calling 'NuGet'::'InstallPackage', '$aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\UXVzZXJPYmplY3Q=\MC4yLjMw\aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\cG93ZXJzaGVsbGdldA=='.
DEBUG: 00:00:07.2285043 Calling 'NuGetRequest'::'GetPackageByFastpath', '$aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\UXVzZXJPYmplY3Q=\MC4yLjMw\aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\cG93ZXJzaGVsbGdldA=='.
DEBUG: 00:00:07.2294477 Calling 'NuGetRequest'::'ResolvePackageSource', 'https://www.powershellgallery.com/api/v2'.
DEBUG: 00:00:07.2302608 Calling 'NuGetRequest'::'FindRegisteredSource', 'https://www.powershellgallery.com/api/v2'.
DEBUG: 00:00:07.2354596 Source 'https://www.powershellgallery.com/api/v2' is not one of the registered sources in 'NuGet' provider.
DEBUG: 00:00:07.3336518 Calling 'NuGetPackageRepository'::'FindPackage', 'QuserObject'.
DEBUG: 00:00:07.3346969 Calling 'NuGetPackageFeed2'::'FindPackage', 'QuserObject'.
DEBUG: 00:00:07.3355753 Calling 'NuGetClient'::'FindPackage'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'' for ''.
DEBUG: 00:00:07.3372679 Downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:07.7535280 Completed downloading 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='QuserObject'&$skip=0&$top=40'.
DEBUG: 00:00:07.7568476 '22' packages received in the last request.
DEBUG: 00:00:07.7720642 'Package version' is '0.2.30'.
DEBUG: 00:00:07.7734516 'Request's Destination' is 'C:\Windows\TEMP\232700364'.
DEBUG: 00:00:07.7744192 Calling 'NuGetPackageRepository'::'InstallPackage'.
DEBUG: 00:00:07.7755779 Calling 'NuGetFilesFeed2'::'InstallPackage'.
DEBUG: 00:00:07.7794337 Calling 'NuGetFilesFeed2'::'InstallPackage', '$aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\UXVzZXJPYmplY3Q=\MC4yLjMw\aHR0cHM6Ly93d3cucG93ZXJzaGVsbGdhbGxlcnkuY29tL2FwaS92Mg==\cG93ZXJzaGVsbGdldA=='.
DEBUG: 00:00:07.7805837 Calling 'NuGetClient'::'GetPackageDependencies'.
DEBUG: 00:00:07.7823905 Returning the call 'NuGetClient'::'GetPackageDependencies'.
DEBUG: 00:00:07.7846902 Calling 'NuGetClient'::'InstallPackage'.
VERBOSE: InstallPackage' - name='QuserObject', version='0.2.30',destination='C:\Windows\TEMP\232700364'
VERBOSE: DownloadPackage' - name='QuserObject', version='0.2.30',destination='C:\Windows\TEMP\232700364\QuserObject.0.2.30\QuserObject.0.2.30.nupkg', uri='https://www.powershellgallery.com/api/v2/package/QuserObject/0.2.30'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/QuserObject/0.2.30'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/QuserObject/0.2.30'.
VERBOSE: Completed downloading 'QuserObject'.
DEBUG: 00:00:08.2412013 Calling 'NuGetClient'::'InstallPackageLocal'.
VERBOSE: InstallPackageLocal' - name='QuserObject', version='0.2.30',destination='C:\Windows\TEMP\232700364'
DEBUG: 00:00:08.2443678 C:\Windows\TEMP\232700364\QuserObject.0.2.30\QuserObject.0.2.30.nupkg
DEBUG: 00:00:08.3652682 Returning the call 'NuGetClient'::'InstallPackageLocal'.
DEBUG: 00:00:08.4317828 Returning the call 'NuGetClient'::'InstallSinglePackage'.
DEBUG: 00:00:08.4431653 Returning the call 'NuGetFilesFeed2'::'InstallPackage'.
VERBOSE: Validating the 'QuserObject' module contents under 'C:\Windows\TEMP\232700364\QuserObject.0.2.30' path.
VERBOSE: Test-ModuleManifest successfully validated the module manifest file 'C:\Windows\TEMP\232700364\QuserObject.0.2.30'.
VERBOSE: Validating the authenticode signature and publisher of the catalog file or module manifest file of the module 'QuserObject'.
VERBOSE: Catalog file 'QuserObject.cat' is not found in the contents of the module 'QuserObject' being installed.
DEBUG: 00:00:09.0224164 Using the 'QuserObject.psd1' file for getting the authenticode signature.
DEBUG: 00:00:09.0766633 For publisher validation, current module 'QuserObject' with version '0.2.30' with publisher name '' from root certificate authority ''. Is this module signed by Microsoft: 'False'.
VERBOSE: Checking for possible command collisions for the module 'QuserObject' commands.
VERBOSE: Module 'QuserObject' was installed successfully to path 'C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules\QuserObject\0.2.30'.
DEBUG: 00:00:09.4561789 Done calling powershell «Install-Package» «PSModule»
**********************
Command start time: 20201112101514
**********************
PS C:\> Get-Module QuserObject -ListAvailable
**********************
Command start time: 20201112105439
**********************
PS C:\> [System.Environment]::GetFolderPath('MyDocuments')
C:\Windows\system32\config\systemprofile\Documents
**********************
Command start time: 20201112105447
**********************
PS C:\> $env:PSModulePath.Split(';')[0]
PowerShell\Modules
**********************
Command start time: 20201112105525
**********************
PS C:\> $psmp = $env:PSModulePath.Split(';')
**********************
Command start time: 20201112105716
**********************
PS C:\> $psmp[0] = Join-Path ([System.Environment]::GetFolderPath('MyDocuments')) $env:PSModulePath.Split(';')[0]
**********************
Command start time: 20201112105721
**********************
PS C:\> $psmp
C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7\Modules
\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
**********************
Command start time: 20201112105746
**********************
PS C:\> $env:PSModulePath = $psmp -join ';'
**********************
Command start time: 20201112105939
**********************
PS C:\> $env:PSModulePath
C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
**********************
Command start time: 20201112105946
**********************
PS C:\> Get-Module QuserObject -ListAvailable

    Directory:
C:\Windows\system32\config\systemprofile\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition
---------- -------    ---------- ----                                ---------
Script     0.2.30                QuserObject                         Desk

**********************
Command start time: 20201112105953
**********************
PS C:\> Stop-Transcript
**********************
PowerShell transcript end
End time: 20201112105953
**********************

Restarting PowerShell or fixing the path manually will allow the PS Module to be discoverable. Walked through everything a bit on my blog.

Environment data

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

VertigoRay avatar Nov 12 '20 18:11 VertigoRay

On a clean system default $env:PSModulePath should consist of 3 parts: <personalModulePath>;<sharedModulePath>;<psHomeModulePath>. <personalModulePath> - is the SpecialFolder.MyDocuments location of current user (in this case - nt authority\system) that seems to be where you intend to install the module. In the code it is done using Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Utils.ModuleDirectory); GetFolderPath API has a note that it returns the path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string (""), which is the behaviour that is described in your blog post - [System.Environment]::GetFolderPath('MyDocuments') was returning empty string until the folder was manually created.

@SteveL-MSFT FYI.

anmenaga avatar Nov 15 '20 01:11 anmenaga

Also, @VertigoRay in Steps to reproduce and Expected behavior you have WindowsPowerShell substring in PSModulePath (even though Environment data specifies PSVersion 7.1.0) - that is not usual for PS Core. I guess that you copied this from Windows PS repro, because you mention in your blog that you've ran same repro on Windows PowerShell as well?

anmenaga avatar Nov 15 '20 01:11 anmenaga

Apologies for the confusion. I accidentally pulled those snippets from Windows PowerShell. The issue exists in both PowerShell and Windows PowerShell, albeit in slightly different forms.

  • In Windows PowerShell, you have to create the documents folder in order to fix the issue.
  • In PowerShell, the documents folder will get created during Install-Module; however, the module cannot be found until the next time PowerShell is run.

Thank you for your time @anmenaga; I understand the issue. However, I believe that if PowerShell is not going to install, it should error out completely and prevent installation. However, it seems that PowerShell does create the Documents folder and install the module, but then cannot find the module afterwards. As I said in the OP, "Restarting PowerShell or fixing the path manually will allow the PS Module to be discoverable." So, PowerShell should re-initialize $env:PSModulePath to allow itself to find the module since it fixes things.

VertigoRay avatar Nov 20 '20 04:11 VertigoRay

"Restarting PowerShell or fixing the path manually will allow the PS Module to be discoverable." Is there a chance that PowerShell was restarted After path was manually created?

I'm pretty sure that PS Engine does Not create paths in $env:PSModulePath; it just tries to access them. It also re-initializes $env:PSModulePath basically every time when it is looking to load a module.

This feels like a defect in Install-Module / PowerShellGet cc @alerickson

anmenaga avatar Nov 25 '20 00:11 anmenaga