Skip to content

Commit 62cb759

Browse files
DearingDevHeyItsGilbertclaudesit-mdmpiederiet
authored
fix: pass -Scope correctly when Target=CurrentUser for PowerShellGet package (#167)
## What this changes Fixes a variable reference bug in PSDepend/PSDependScripts/Package.ps1 where the elseif condition checked $Scope (undefined at that point) instead of $Dependency.Target. As a result, -Scope was never passed to Install-Package when Target = 'CurrentUser', causing an elevation prompt. The Target→Scope logic has been restructured to match the pattern used in PSGalleryModule.ps1. ## Why When invoking PSDepend with -Target CurrentUser for PowerShellGet packages, users were unexpectedly prompted for elevation because the scope was never set. Closes #130 ## Type of change - [X] Bug fix (non-breaking change that corrects incorrect behavior) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that changes existing behavior) - [ ] Chore / refactor / documentation (no behavior change) ## Checklist - [ ] Pester tests added or updated to cover the change - [X] `Invoke-psake Analyze` passes locally with no new warnings - [X] `Invoke-psake Test` passes locally on at least one platform - [ ] `CHANGELOG.md` updated (required for any user-facing change) - [ ] Documentation updated if behavior changed ## Additional notes The fix mirrors the existing logic in PSGalleryModule.ps1 which handles the same Target→Scope mapping correctly. --------- Co-authored-by: Gilbert Sanchez <me@gilbertsanchez.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Marcel Dutt <41046352+sit-md@users.noreply.github.com> Co-authored-by: Maarten Piederiet <mpiederiet@users.noreply.github.com>
1 parent b077f24 commit 62cb759

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

PSDepend/PSDependScripts/Package.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ If($ThisProvider -eq 'PowerShellGet')
124124
if(-not $Dependency.Target)
125125
{
126126
$Scope = 'AllUsers'
127-
$InstallParam.Add('Scope', $Scope)
128127
}
129-
elseif($ValidScope -contains $Scope)
128+
else
130129
{
131130
$Scope = $Dependency.Target
131+
}
132+
if($ValidScope -contains $Scope)
133+
{
132134
$InstallParam.Add('Scope', $Scope)
133135
}
134136
}

0 commit comments

Comments
 (0)