Compare commits

...

5 Commits

Author SHA1 Message Date
45c403e19b Made new function an actual function 2025-06-04 16:54:51 -05:00
cd2aebf1ff More changes to make platform-agnostic 2025-06-04 16:43:25 -05:00
ddef660727 Finish out Import-Config... 2025-05-14 17:44:44 -05:00
d02ab2b22b Add Import-Config function 2025-05-14 17:43:12 -05:00
10458daf98 Fix typo 2025-05-14 17:42:54 -05:00
2 changed files with 118 additions and 21 deletions

View File

@@ -88,9 +88,9 @@ ForEach ($Uri in $AddonUris) {
$UriStatusCode = (Invoke-WebRequest -Uri $Uri -UseBasicParsing -Method Head -SkipHttpErrorCheck).StatusCode
If ($UriStatusCode -eq 200) {
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)"
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 {
Write-Host "Error encountered importing addon"
@@ -102,6 +102,8 @@ ForEach ($Uri in $AddonUris) {
Exit $UriStatusCode
}
}
Import-Modules $ModuleNames
#endregion Imports
#region Functions
@@ -129,25 +131,7 @@ If (-Not $NoLog) {
If (-not $LogDir) {
$LogDir = $AppDir
}
Add-LogEntry (Start-Transcript "$AppDir\$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
}
Add-LogEntry (Start-Transcript "$LogDir\$ThisScript.log" -Append)
}
#endregion Prep

View File

@@ -218,6 +218,61 @@ Function Initialize-PSGallery {
}
}
Function 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 () {
<#
.SYNOPSIS
@@ -393,6 +448,64 @@ Function Import-CSVConfig () {
}
}
Function Import-Config () {
<#
.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)] [ValidateNotNullOrEmpty()] $ConfigFile
)
If (Test-Path -Path $ConfigFile) {
Try {
Switch ((Get-Item -Path $ConfigFile).Extension.ToLower()) {
{ @( ".yml", ".yaml").Contains($_) } { Return (Import-YAMLConfig $ConfigFile) }
{ @( ".jsn", ".json").Contains($_) } { Return (Import-JSONConfig $ConfigFile) }
{ @( ".csv").Contains($_) } { Return (Import-CSVConfig $ConfigFile) }
}
}
Catch {
Add-LogEntry "Error loading config file! Please make sure the correct path was provided, and that it is a properly formatted CSV file" -As Error
Write-Host $_
Exit
}
}
Else {
Add-LogEntry "Error loading config file! Please make sure the correct path was provided, and that it is a properly formatted file" -As Error
Write-Host $_
Exit
}
}
Function Set-RegistryKey {
Param(
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] $TestPath,