Skip to content

Commit 1da6a27

Browse files
authored
Merge pull request #126 from o365soa/jondev-5828
Limit module installation from PSGallery to MaxVersion
2 parents f54c72b + b23997a commit 1da6a27

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Settings within the .vscode directory
2+
.vscode/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The following Microsoft security assessments have several prerequisites that nee
77
- Microsoft 365 Foundations - Workload Security Assessment
88
- Security Optimization Assessment for Microsoft Defender
99

10-
The preqrequisites installation script is included in a PowerShell module named SOA.
10+
The prerequisites installation script is included in a PowerShell module named SOA.
1111

1212
## Prerequisites Breakdown
1313

@@ -46,7 +46,7 @@ In order to install the SOA module and run the prerequisites script, you must ha
4646
`Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`
4747

4848
### Permissions
49-
* Local admin (running PowerShell as an adminisrator) is not required unless the Active Directory module needs to be installed (see [below](#active-directory-module)).
49+
* Local admin (running PowerShell as an administrator) is not required unless the Active Directory module needs to be installed (see [below](#active-directory-module)).
5050
* The user installing the prerequisites needs the following roles:
5151
* Application Administrator (or Cloud App Administrator or Privileged Role Administrator), to create the app registration. (If this is not possible, contact the resource delivering the assessment for instructions to manually create the app registration.)
5252
* Billing Administrator, to get the licenses in the tenant.

SOA/SOA-Prerequisites.psm1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,16 +744,29 @@ Function Install-ModuleFromGallery {
744744
[Switch]$Update
745745
)
746746

747+
$InstallArguments = @{}
748+
747749
# Install the module from PSGallery specifying Force
748750
# AllowClobber allows Teams module to be installed when SfBO module is installed/loaded
749751
if (Get-IsAdministrator) {
750-
$Scope = "AllUsers"
752+
$InstallArguments = @{
753+
Scope = "AllUsers"
754+
}
751755
}
752756
else {
753-
$Scope = "CurrentUser"
757+
$InstallArguments = @{
758+
Scope = "CurrentUser"
759+
}
760+
}
761+
762+
$MaxVersion = ($script:ModuleVersions | Where-Object {$_.ModuleName -eq $Module}).MaximumVersion
763+
if ($MaxVersion) {
764+
Write-Verbose "A MaximumVersion of $MaxVersion was specified for $Module. Only this version will be installed from the PSGallery."
765+
766+
$InstallArguments.Add("RequiredVersion",$MaxVersion)
754767
}
755768

756-
Install-Module $Module -Force -Scope:$Scope -AllowClobber
769+
Install-Module $Module -Force -AllowClobber @InstallArguments
757770

758771
If($Update) {
759772
# Remove old versions of the module

0 commit comments

Comments
 (0)