From f245396c1aa61a5b039bca60c92d02857773ad4a Mon Sep 17 00:00:00 2001 From: buidav <105074908+buidav@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:34:13 -0700 Subject: [PATCH 1/2] add scope variable to initialize-scuba --- PowerShell/ScubaGear/Modules/Support/Support.psm1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/Support/Support.psm1 b/PowerShell/ScubaGear/Modules/Support/Support.psm1 index 9ca7175e54..c4c4c52585 100644 --- a/PowerShell/ScubaGear/Modules/Support/Support.psm1 +++ b/PowerShell/ScubaGear/Modules/Support/Support.psm1 @@ -91,7 +91,12 @@ function Initialize-SCuBA { [Parameter(Mandatory=$false, HelpMessage = 'Directory to contain ScubaGear artifacts. Defaults to .')] [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...' @@ -164,7 +169,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}." } @@ -177,7 +182,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}." @@ -187,7 +192,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}." From 7b912b6908915b2d692440b3f621f868b019c77f Mon Sep 17 00:00:00 2001 From: buidav <105074908+buidav@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:44:30 -0700 Subject: [PATCH 2/2] add another example --- PowerShell/ScubaGear/Modules/Support/Support.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PowerShell/ScubaGear/Modules/Support/Support.psm1 b/PowerShell/ScubaGear/Modules/Support/Support.psm1 index c4c4c52585..ba0204a305 100644 --- a/PowerShell/ScubaGear/Modules/Support/Support.psm1 +++ b/PowerShell/ScubaGear/Modules/Support/Support.psm1 @@ -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.