Add additional function, require PS 6.2 requirement

This commit is contained in:
2025-01-28 12:14:03 -06:00
parent 0c08993945
commit c014bc7ec5

View File

@@ -1,9 +1,7 @@
#Requires -Version 6.2
Function Test-CommandExists { Function Test-CommandExists {
<# <#
.SYNOPSIS .SYNOPSIS
A brief description of the function or script. Returns true if a command is present in PowerShell
.DESCRIPTION .DESCRIPTION
A longer description. A longer description.
@@ -93,29 +91,17 @@ Function Add-LogEntry {
[Parameter(Mandatory = $false)] [ValidateSet('Notify', 'Warning', 'Error')]$As, [Parameter(Mandatory = $false)] [ValidateSet('Notify', 'Warning', 'Error')]$As,
[Parameter(Mandatory = $false)] [Switch]$NewLine [Parameter(Mandatory = $false)] [Switch]$NewLine
) )
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Switch ($As) { Switch ($As) {
"Notify" { "Notify" { $FGC = "Cyan" }
$FGC = "Cyan" "Warning" { $FGC = "Yellow" }
} "Error" { $FGC = "Red" }
"Warning" { Default { $FGC = "White" }
$FGC = "Yellow"
}
"Error" {
$FGC = "Red"
}
Default {
$FGC = "White"
}
} }
If ($Newline) { $Output += "`n" }
If ($Newline) { $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Write-Host "`n[$Timestamp] $Message" -ForegroundColor $FGC $Output += "[$Timestamp] $Message"
} Write-Host $Output -ForegroundColor $FGC
Else {
Write-Host "[$Timestamp] $Message" -ForegroundColor $FGC
}
} }
Function Add-ListItem () { Function Add-ListItem () {
@@ -154,9 +140,13 @@ Function Add-ListItem () {
#> #>
Param ( Param (
[Parameter(Mandatory = $true)] [ValidateNotNullorEmpty()]$Message [Parameter(Mandatory = $true)] [ValidateNotNullorEmpty()]$Message,
[Parameter(Mandatory = $false)] [Int16] $Indent = 0
) )
Write-Host " * $Message"
For ($Counter = 0; $Counter -le $Indent; $Counter++) { $Output += "`t" }
$Output += "* $Message"
Write-Host $Output
} }
Function Start-Logging { Function Start-Logging {
@@ -210,11 +200,63 @@ Function Start-Logging {
} }
If ($Append) { If ($Append) {
Add-LogEntry (Start-Transcript -Path "$LogDir\$ScriptName.log" -UseMinimalHeader -Append) Add-LogEntry (Start-Transcript -Path "$LogDir\$ScriptName.log" -Append)
} }
Else { Else {
Add-LogEntry (Start-Transcript -Path "$LogDir\$ScriptName.log" -UseMinimalHeader) Add-LogEntry (Start-Transcript -Path "$LogDir\$ScriptName.log")
}
}
Function Import-JSONConfig () {
<#
.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 (Get-Content -Raw -Path $ConfigFile | ConvertFrom-Json)
}
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-Host $_
Exit 1
}
}
Else {
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-Host $_
Exit 1
} }
} }