Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ed3ac13
Change default scope in Install-Module and Install-Script
alerickson Aug 22, 2018
3191108
Delete whitespace
alerickson Aug 22, 2018
d891b92
Change default scope for non-Windows to CurrentUser
alerickson Aug 24, 2018
913d71c
Add tests to install module/script test files, delete previous tests
alerickson Aug 29, 2018
d58b423
Update tests
alerickson Aug 30, 2018
11322c4
Added scope changes to Install-PackageUtility, modified tests
alerickson Aug 30, 2018
92e8003
Add scope condition for non-windows, update tests
alerickson Aug 31, 2018
c9e9f15
Add unix credentials
alerickson Sep 4, 2018
47d00e1
Travis test
alerickson Sep 4, 2018
0224557
Add print statements to tests for location installation verification
alerickson Sep 4, 2018
976a2e6
Add print statements
alerickson Sep 4, 2018
2797552
Add cleanup for unix user
alerickson Sep 5, 2018
ac42abe
Change installed location assertions in tests
alerickson Sep 5, 2018
ba01168
Add tests for Install-Package user scope
alerickson Sep 6, 2018
a8a9014
Update current user scope for non-admin tests
alerickson Sep 6, 2018
5e7c1e8
Update tests for linux
alerickson Sep 7, 2018
33139df
Update tests
alerickson Sep 7, 2018
351ff97
Update tests for windows
alerickson Sep 7, 2018
c06ebb6
Change for windows test
alerickson Sep 7, 2018
b780be3
Change scope to current user for install-packageprovider in tests
alerickson Sep 7, 2018
56bd61c
Reset tests to older version
alerickson Sep 7, 2018
45c1aeb
Change Install-PackageProvider scope to CurrentUser
alerickson Sep 8, 2018
a12d347
root*
alerickson Sep 8, 2018
92d711e
Add print statement-- tests passing locally failing on AppVeyor
alerickson Sep 8, 2018
5821a60
Update print statements
alerickson Sep 9, 2018
854fd34
Update print statements for test
alerickson Sep 9, 2018
cce47b8
Test appveyor
alerickson Sep 9, 2018
851e116
Update allusers test for install script
alerickson Sep 9, 2018
ac8a3a7
Added ErrorVariable to tests
alerickson Sep 9, 2018
2fa6983
Change Windows variable for tests
alerickson Sep 10, 2018
c6e26af
Comment out linux code, rerun tests
alerickson Sep 10, 2018
8249794
InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser
alerickson Sep 11, 2018
58359fe
Incorporate changes from code review
alerickson Sep 11, 2018
a01e9cc
Add pwsh.exe if console is PSCore
alerickson Sep 11, 2018
89d1e15
Incorporate changes from code review
alerickson Sep 12, 2018
7bb9ad0
Merge remote-tracking branch 'upstream/master' into scopeForInstallMo…
alerickson Sep 12, 2018
65e63bf
Update changelog
alerickson Sep 12, 2018
67b1de7
Update changelog, minor changes to tests and install-script
alerickson Sep 12, 2018
46920d1
Enable AppVeyor RDP for current branch
alerickson Sep 12, 2018
f525eca
Add Skip for Core tests, remove RDP for branch
alerickson Sep 12, 2018
3a09f5d
Change 'is windows' check to 'is not core' in install-packageutility
alerickson Sep 12, 2018
702b5e2
Add -NoPathUpdate to Install-Package cmd in Publish-Script test
alerickson Sep 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## 2.0.0
Breaking Change
- Default installation scope for Install-Module, Install-Script, and Install-Package has changed. For Windows PowerShell (version 5.1 or below), the default scope is AllUsers when running in an elevated session, and CurrentUser at all other times.
For PowerShell version 6.0.0 and above, the default installation scope is always CurrentUser.


## 1.6.7

Bug fixes
Expand Down
4 changes: 2 additions & 2 deletions PowerShellGet/PSGet.Resource.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ConvertFrom-StringData @'
RequiredVersionAllowedOnlyWithSingleModuleName=The RequiredVersion parameter is allowed only when a single module name is specified as the value of the Name parameter, without any wildcard characters.
MinimumVersionIsGreaterThanMaximumVersion=The specified MinimumVersion '{0}' is greater than the specified MaximumVersion '{1}'.
AllowPrereleaseRequiredToUsePrereleaseStringInVersion=The '-AllowPrerelease' parameter must be specified when using the Prerelease string in MinimumVersion, MaximumVersion, or RequiredVersion.
InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser=Administrator rights are required to install modules in '{0}'. Log on to the computer with an account that has Administrator rights, and then try again, or install '{1}' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser=Administrator rights are required to install scripts in '{0}'. Log on to the computer with an account that has Administrator rights, and then try again, or install '{1}' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
InstallModuleAdminPrivilegeRequiredForAllUsersScope=Administrator rights are required to install modules in '{0}'. Log on to the computer with an account that has Administrator rights, and then try again, or install '{1}' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
InstallScriptAdminPrivilegeRequiredForAllUsersScope=Administrator rights are required to install scripts in '{0}'. Log on to the computer with an account that has Administrator rights, and then try again, or install '{1}' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
AdministratorRightsNeededOrSpecifyCurrentUserScope=Administrator rights are required to install or update. Log on to the computer with an account that has Administrator rights, and then try again, or install by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
VersionParametersAreAllowedOnlyWithSingleName=The RequiredVersion, MinimumVersion, MaximumVersion, AllVersions or AllowPrerelease parameters are allowed only when you specify a single name as the value of the Name parameter, without any wildcard characters.
PathIsNotADirectory=The specified path '{0}' is not a valid directory.
Expand Down
8 changes: 7 additions & 1 deletion PowerShellGet/PowerShellGet.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'PSModule.psm1'
ModuleVersion = '1.6.7'
ModuleVersion = '2.0.0'
GUID = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Expand Down Expand Up @@ -54,6 +54,12 @@ PrivateData = @{
ProjectUri = 'https://go.microsoft.com/fwlink/?LinkId=828955'
LicenseUri = 'https://go.microsoft.com/fwlink/?LinkId=829061'
ReleaseNotes = @'
## 2.0.0

Breaking Change
- Default installation scope for Install-Module, Install-Script, and Install-Package has changed. For Windows PowerShell (version 5.1 or below), the default scope is AllUsers when running in an elevated session, and CurrentUser at all other times.
For PowerShell version 6.0.0 and above, the default installation scope is always CurrentUser.

## 1.6.7

Bug fixes
Expand Down
27 changes: 15 additions & 12 deletions PowerShellGet/private/functions/Install-PackageUtility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ function Install-PackageUtility

if($artifactType -eq $script:PSArtifactTypeScript)
{
$AdminPrivilegeErrorMessage = $LocalizedData.InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser -f @($script:ProgramFilesScriptsPath, $script:MyDocumentsScriptsPath)
$AdminPrivilegeErrorId = 'InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser'
$AdminPrivilegeErrorMessage = $LocalizedData.InstallScriptAdminPrivilegeRequiredForAllUsersScope -f @($script:ProgramFilesScriptsPath, $script:MyDocumentsScriptsPath)
$AdminPrivilegeErrorId = 'InstallScriptAdminPrivilegeRequiredForAllUsersScope'
}
else
{
$AdminPrivilegeErrorMessage = $LocalizedData.InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser -f @($script:programFilesModulesPath, $script:MyDocumentsModulesPath)
$AdminPrivilegeErrorId = 'InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser'
$AdminPrivilegeErrorMessage = $LocalizedData.InstallModuleAdminPrivilegeRequiredForAllUsersScope -f @($script:programFilesModulesPath, $script:MyDocumentsModulesPath)
$AdminPrivilegeErrorId = 'InstallModuleAdminPrivilegeRequiredForAllUsersScope'
}

$installUpdate = $false
Expand Down Expand Up @@ -101,7 +101,7 @@ function Install-PackageUtility

if(-not (Test-RunningAsElevated))
{
# Throw an error when Install-Module/Script is used as a non-admin user and '-Scope CurrentUser' is not specified
# Throw an error when Install-Module/Script is used as a non-admin user and '-Scope AllUsers'
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $AdminPrivilegeErrorMessage `
-ErrorId $AdminPrivilegeErrorId `
Expand All @@ -118,14 +118,17 @@ function Install-PackageUtility
$moduleDestination = $Location
$scriptDestination = $Location
}
# if no scope and no destination path and not elevated, then raise an error
elseif(-not (Test-RunningAsElevated))
elseif(-not $script:IsCoreCLR -and (Test-RunningAsElevated))
{
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $AdminPrivilegeErrorMessage `
-ErrorId $AdminPrivilegeErrorId `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
# If Windows and elevated default scope will be all users
$scriptDestination = $script:ProgramFilesScriptsPath
$moduleDestination = $script:ProgramFilesModulesPath
}
else
{
# If non-Windows or non-elevated default scope will be current user
$scriptDestination = $script:MyDocumentsScriptsPath
$moduleDestination = $script:MyDocumentsModulesPath
}

if($options.ContainsKey('SkipPublisherCheck'))
Expand Down
21 changes: 16 additions & 5 deletions PowerShellGet/public/psgetfunctions/Install-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Install-Module
[Parameter()]
[ValidateSet("CurrentUser","AllUsers")]
[string]
$Scope = "AllUsers",
$Scope,

[Parameter(ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -91,18 +91,29 @@ function Install-Module
{
Get-PSGalleryApiAvailability -Repository $Repository

if(-not (Test-RunningAsElevated) -and ($Scope -ne "CurrentUser"))
if($Scope -eq "AllUsers" -and -not (Test-RunningAsElevated))
{
# Throw an error when Install-Module is used as a non-admin user and '-Scope CurrentUser' is not specified
$message = $LocalizedData.InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser -f @($script:programFilesModulesPath, $script:MyDocumentsModulesPath)
# Throw an error when Install-Module is used as a non-admin user and '-Scope AllUsers'
$message = $LocalizedData.InstallModuleAdminPrivilegeRequiredForAllUsersScope -f @($script:programFilesModulesPath, $script:MyDocumentsModulesPath)

ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
-ErrorId "InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser" `
-ErrorId "InstallModuleAdminPrivilegeRequiredForAllUsersScope" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
}

# If no scope is specified, default installation will be to AllUsers only
# If running admin on Windows with PowerShell less than v6.
if (-not $Scope)
{
$Scope = "CurrentUser"
if(-not $script:IsCoreCLR -and (Test-RunningAsElevated))
{
$Scope = "AllUsers"
}
}

Install-NuGetClientBinaries -CallerPSCmdlet $PSCmdlet -Proxy $Proxy -ProxyCredential $ProxyCredential

# Module names already tried in the current pipeline for InputObject parameterset
Expand Down
24 changes: 17 additions & 7 deletions PowerShellGet/public/psgetfunctions/Install-Script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function Install-Script
[Parameter()]
[ValidateSet("CurrentUser","AllUsers")]
[string]
$Scope = 'AllUsers',
$Scope,

[Parameter()]
[Switch]
Expand Down Expand Up @@ -87,19 +87,29 @@ function Install-Script
{
Get-PSGalleryApiAvailability -Repository $Repository

if(-not (Test-RunningAsElevated) -and ($Scope -ne "CurrentUser"))
if($Scope -eq "AllUsers" -and -not (Test-RunningAsElevated))
{
# Throw an error when Install-Script is used as a non-admin user and '-Scope CurrentUser' is not specified
$AdminPrivilegeErrorMessage = $LocalizedData.InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser -f @($script:ProgramFilesScriptsPath, $script:MyDocumentsScriptsPath)
$AdminPrivilegeErrorId = 'InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser'
# Throw an error when Install-Script is used as a non-admin user and '-Scope AllUsers'
$message = $LocalizedData.InstallScriptAdminPrivilegeRequiredForAllUsersScope -f @($script:ProgramFilesScriptsPath, $script:MyDocumentsScriptsPath)

ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $AdminPrivilegeErrorMessage `
-ErrorId $AdminPrivilegeErrorId `
-ExceptionMessage $message `
-ErrorId "InstallScriptAdminPrivilegeRequiredForAllUsersScope" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
}

# If no scope is specified, default installation will be to AllUsers only
# If running admin on Windows with PowerShell less than v6.
if (-not $Scope)
{
$Scope = "CurrentUser"
if(-not $script:IsCoreCLR -and (Test-RunningAsElevated))
{
$Scope = "AllUsers"
}
}

# Check and add the scope path to PATH environment variable
if($Scope -eq 'AllUsers')
{
Expand Down
Loading