Update tools and template

This commit is contained in:
2025-05-14 16:40:31 -05:00
parent 262c8fb095
commit 3a427ec324
2 changed files with 177 additions and 67 deletions

View File

@@ -139,6 +139,85 @@ Function Add-ListItem () {
Write-Host $Output
}
Function Initialize-PSGallery {
<#
.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.
#>
Add-LogEntry "Preparing system to download modules"
If ([Net.ServicePointManager]::SecurityProtocol -ne [Net.SecurityProtocolType]::SystemDefault) {
Add-LogEntry "Upgrading TLS security protocol to 1.2"
Try {
[Net.ServicePointManager]::SecurityProtocol = @([Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12)
}
Catch {
Add-LogEntry "Upgrade failed, script is exiting" -As Error
Exit 1
}
}
If ((Get-PackageProvider).Name -notcontains "NuGet") {
Add-LogEntry "Installing NuGet package provider"
Try {
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -ErrorAction Stop
}
Catch {
Add-LogEntry "Installation failed, script is exiting" -As Error
Exit 1
}
}
$PSRepos = Get-PSRepository
If ($PSRepos.Name -notcontains "PSGallery") {
Add-LogEntry "Registering PSGallery as script source"
Try {
Register-PSRepository -Default -InstallationPolicy Trusted -ErrorAction Stop
}
Catch {
Add-LogEntry "Change failed, script is exiting" -As Error
Exit 1
}
}
ElseIf ($PSRepos | Where-Object { $_.Name -eq "PSGallery" -and $_.InstallationPolicy -ne "Trusted" }) {
Add-LogEntry "Trusting scripts from PSGallery"
Try {
Set-PSRepository PSGallery -InstallationPolicy Trusted -ErrorAction Stop
}
Catch {
Add-LogEntry "Change failed, script is exiting" -As Error
Exit 1
}
}
}
Function Import-JSONConfig () {
<#
.SYNOPSIS
@@ -230,28 +309,88 @@ Function Import-YAMLConfig () {
Param (
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [String] $ConfigFile
)
If (Test-CommandExists -Command "ConvertFrom-Yaml") {
If (Test-Path -Path $ConfigFile) {
Try {
Return (Get-Content -Raw -Path $ConfigFile | ConvertFrom-Yaml)
}
Catch {
Add-LogEntry "Error loading config file! Please make sure the correct path was provided, and that it is a properly formatted JSON file" -As Error
Write-Output $_
Exit 1
}
If ( -Not (Get-Module -ListAvailable -Name "powershell-yaml")) {
Add-LogEntry "Module `"powershell-yaml`" not present, but needed for YAML imports. Adding..."
Try {
Initialize-PSGallery
Install-Module -Name "powershell-yaml" -Scope CurrentUser -Force -AllowClober
}
Else {
Catch {
Add-LogEntry "Module failed to install automatically! Manaully install the module, then re-run the script." -As Error
Exit 1
}
}
If (Test-Path -Path $ConfigFile) {
Try {
Return (Get-Content -Raw -Path $ConfigFile | ConvertFrom-Yaml)
}
Catch {
Add-LogEntry "Error loading config file! Please make sure the correct path was provided, and that it is a properly formatted JSON file" -As Error
Write-Output $_
Exit 1
}
}
Else {
Add-LogEntry "Cannot import YAML config, module `"powershell-yaml`" is not installed"
Add-LogEntry "Error loading config file! Please make sure the correct path was provided, and that it is a properly formatted JSON file" -As Error
Write-Output $_
Exit 1
}
}
}
Function Import-CSVConfig () {
<#
.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 {
Return (Import-Csv $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 CSV file" -As Error
Write-Host $_
Exit
}
}
Function Set-RegistryKey {