dsccommunity / DscResource.Common

This module contains common functions that are used in DSC resources.
https://dsccommunity.org
MIT License
9 stars 9 forks source link

Get-PSModulePath: Fails with unclear exception when user is SYSTEM and `Scope` is `CurrentUser` #122

Closed johlju closed 2 months ago

johlju commented 7 months ago

Problem description

When the command Get-PSModulePath is called as the user SYSTEM with the parameter Scope set to CurrentUser then if fails with an unclear exception.

Verbose logs

PS> whoami
nt authority\system
PS> import-module .\output\RequiredModules\DscResource.Common
PS> Get-PSModulePath -Scope CurrentUser
Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\source\..\output\RequiredModules\DscResource.Common\0.17.1\DscResource.Common.psm1:3221
char:41
+                         Join-Path -Path $documentsFolder -ChildPath ' ...
+                                         ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Join
   PathCommand

PS> Get-PSModulePath -Scope AllUsers
C:\Program Files\WindowsPowerShell\Modules

How to reproduce

Run the command Get-PSModulePath -Scope CurrentUser as SYSTEM.

Expected behavior

Should return an error message that is more clear what is going on.

Current behavior

Fails with an unclear message.

Suggested solution

Should throw a clear message saying that the path retrieved was $null and possible output the current user in the error message ($env:USERNAME on WIndows and $env:USER on Linux and macOS). 🤔

Operating system the target node is running

OsName               : Microsoft Windows 11 Business
OsOperatingSystemSKU : 48
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage           : en-US
OsMuiLanguages       : {en-US, en-GB}

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.22621.2506
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2506
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module version used

0.17.0