Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Users to Specify Installing to AllUsers via new $Scope Variable in Initialize-SCuBA #1388

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions PowerShell/ScubaGear/Modules/Support/Support.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function Initialize-SCuBA {
existing module will not be updated to th latest version.
.EXAMPLE
Initialize-SCuBA
.EXAMPLE
Initalize-SCuBA -Scope AllUsers
Install all dependent PowerShell modules in a location that's accessible to all users of the computer.
.NOTES
Executing the script with no switches set will install the latest
version of a module if not already installed.
Expand Down Expand Up @@ -91,7 +94,12 @@ function Initialize-SCuBA {
[Parameter(Mandatory=$false, HelpMessage = 'Directory to contain ScubaGear artifacts. Defaults to <home>.')]
[ValidateScript({Test-Path -Path $_ -PathType Container})]
[string]
$ScubaParentDirectory = $env:USERPROFILE
$ScubaParentDirectory = $env:USERPROFILE,

[Parameter(Mandatory=$false, HelpMessage = 'Specifies the Install-Module scope of the dependent PowerShell modules. Acceptable values are AllUsers and CurrentUser. Defaults to CurrentUser')]
[ValidateSet('CurrentUser','AllUsers')]
[string]
$Scope = 'CurrentUser'
)

Write-Output 'Initializing ScubaGear...'
Expand Down Expand Up @@ -164,7 +172,7 @@ function Initialize-SCuBA {
Install-Module -Name $ModuleName `
-Force `
-AllowClobber `
-Scope CurrentUser `
-Scope "$($Scope)" `
-MaximumVersion $Module.MaximumVersion
Write-Information -MessageData "Re-installing module to latest acceptable version: ${ModuleName}."
}
Expand All @@ -177,7 +185,7 @@ function Initialize-SCuBA {
Install-Module -Name $ModuleName `
-Force `
-AllowClobber `
-Scope CurrentUser `
-Scope "$($Scope)" `
-MaximumVersion $Module.MaximumVersion
$MaxInstalledVersion = (Get-Module -ListAvailable -Name $ModuleName | Sort-Object Version -Descending | Select-Object Version -First 1).Version
Write-Information -MessageData "${ModuleName}: ${HighestInstalledVersion} updated to version ${MaxInstalledVersion}."
Expand All @@ -187,7 +195,7 @@ function Initialize-SCuBA {
else {
Install-Module -Name $ModuleName `
-AllowClobber `
-Scope CurrentUser `
-Scope "$($Scope)" `
-MaximumVersion $Module.MaximumVersion
$MaxInstalledVersion = (Get-Module -ListAvailable -Name $ModuleName | Sort-Object Version -Descending | Select-Object Version -First 1).Version
Write-Information -MessageData "Installed the latest acceptable version of ${ModuleName}: ${MaxInstalledVersion}."
Expand Down
Loading