More changes to make platform-agnostic

This commit is contained in:
2025-06-04 16:43:25 -05:00
parent ddef660727
commit cd2aebf1ff
2 changed files with 59 additions and 20 deletions

View File

@@ -88,9 +88,9 @@ ForEach ($Uri in $AddonUris) {
$UriStatusCode = (Invoke-WebRequest -Uri $Uri -UseBasicParsing -Method Head -SkipHttpErrorCheck).StatusCode $UriStatusCode = (Invoke-WebRequest -Uri $Uri -UseBasicParsing -Method Head -SkipHttpErrorCheck).StatusCode
If ($UriStatusCode -eq 200) { If ($UriStatusCode -eq 200) {
Try { Try {
Invoke-WebRequest -Uri $Uri -OutFile "$Env:Temp\$(Split-Path -Path $Uri -Leaf)" -ErrorAction Stop Invoke-WebRequest -Uri $Uri -OutFile "$([System.IO.Path]::GetTempPath())\$(Split-Path -Path $Uri -Leaf)" -ErrorAction Stop
Write-Host "Importing addon: $(Split-Path -Path $Uri -Leaf)" Write-Host "Importing addon: $(Split-Path -Path $Uri -Leaf)"
Import-Module -Name "$Env:Temp\$(Split-Path -Path $Uri -Leaf)" -Force Import-Module -Name "$([System.IO.Path]::GetTempPath())\$(Split-Path -Path $Uri -Leaf)" -Force
} }
Catch { Catch {
Write-Host "Error encountered importing addon" Write-Host "Error encountered importing addon"
@@ -102,6 +102,8 @@ ForEach ($Uri in $AddonUris) {
Exit $UriStatusCode Exit $UriStatusCode
} }
} }
Import-Modules $ModuleNames
#endregion Imports #endregion Imports
#region Functions #region Functions
@@ -131,24 +133,6 @@ If (-Not $NoLog) {
} }
Add-LogEntry (Start-Transcript "$LogDir\$ThisScript.log" -Append) Add-LogEntry (Start-Transcript "$LogDir\$ThisScript.log" -Append)
} }
# Load any modules required by script
If ($ModuleNames) {
Initialize-PSGallery
ForEach ($Module in $ModuleNames) {
If (-Not (Get-Module -ListAvailable -Name $Module)) {
Try {
Add-LogEntry "Module `"$Module`" not found, installing"
Install-Module -Name $Module -Scope CurrentUser -Force -AllowClobber
}
Catch {
Add-LogEntry "Module failed to install automatically! Manaully install the module, then re-run the script." -As Error
Exit 1
}
}
Import-Module $Module
}
}
#endregion Prep #endregion Prep
#region Execution #region Execution

View File

@@ -218,6 +218,61 @@ Function Initialize-PSGallery {
} }
} }
Import-Modules {
<#
.SYNOPSIS
A brief description of the function or script.
.DESCRIPTION
A longer description.
.PARAMETER FirstParameter
Description of each of the parameters.
Note:
To make it easier to keep the comments synchronized with changes to the parameters,
the preferred location for parameter documentation comments is not here,
but within the param block, directly above each parameter.
.PARAMETER SecondParameter
Description of each of the parameters.
.INPUTS
Description of objects that can be piped to the script.
.OUTPUTS
Description of objects that are output by the script.
.EXAMPLE
Example of how to run the script.
.LINK
Links to further documentation.
.NOTES
Detail on what the script does, if this is needed.
#>
Param (
[Parameter(Mandatory=$true)] $ModuleList
)
If ($ModuleList) {
Initialize-PSGallery
ForEach ($Module in $ModuleList) {
If (-Not (Get-Module -ListAvailable -Name $Module)) {
Try {
Add-LogEntry "Module `"$Module`" not found, installing"
Install-Module -Name $Module -Scope CurrentUser -Force -AllowClobber
}
Catch {
Add-LogEntry "Module failed to install automatically! Manaully install the module, then re-run the script." -As Error
Exit 1
}
}
Import-Module $Module
}
}
}
Function Import-JSONConfig () { Function Import-JSONConfig () {
<# <#
.SYNOPSIS .SYNOPSIS