179 lines
4.3 KiB
PowerShell
179 lines
4.3 KiB
PowerShell
#Requires -Version 6.2
|
|
|
|
Function Test-CommandExists {
|
|
<#
|
|
.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 (
|
|
$Command
|
|
)
|
|
$OldPreference = $ErrorActionPreference
|
|
$ErrorActionPreference = 'Stop'
|
|
Try {
|
|
If (Get-Command $Command) {
|
|
Return $true
|
|
}
|
|
}
|
|
catch {
|
|
Return $false
|
|
}
|
|
finally {
|
|
$ErrorActionPreference = $OldPreference
|
|
}
|
|
}
|
|
|
|
Function Add-LogEntry {
|
|
<#
|
|
.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()]$Message,
|
|
[Parameter(Mandatory = $false)] [ValidateSet('Notify', 'Warning', 'Error')]$As,
|
|
[Parameter(Mandatory = $false)] [Switch]$NewLine
|
|
)
|
|
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
|
|
|
Switch ($As) {
|
|
"Notify" {
|
|
$FGC = "Cyan"
|
|
}
|
|
"Warning" {
|
|
$FGC = "Yellow"
|
|
}
|
|
"Error" {
|
|
$FGC = "Red"
|
|
}
|
|
Default {
|
|
$FGC = "White"
|
|
}
|
|
}
|
|
|
|
If ($Newline) {
|
|
Write-Host "`n[$Timestamp] $Message" -ForegroundColor $FGC
|
|
}
|
|
Else {
|
|
Write-Host "[$Timestamp] $Message" -ForegroundColor $FGC
|
|
}
|
|
}
|
|
|
|
Function Start-Logging {
|
|
<#
|
|
.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)][String]$ScriptName,
|
|
[String]$LogDir,
|
|
[Switch]$User,
|
|
[Switch]$Append
|
|
)
|
|
If (Not $LogDir -eq $null) {
|
|
If ($User) {
|
|
$LogDir = "$Env:USERPROFILE\Mindfang\$ScriptName"
|
|
}
|
|
Else {
|
|
$LogDir = "$Env:ProgramData\Mindfang\$ScriptName"
|
|
}
|
|
}
|
|
|
|
If ($Append) {
|
|
Add-LogEntry (Start-Transcript -Path "$LogDir\$ScriptName.log" -UseMinimalHeader -Append)
|
|
}
|
|
Else {
|
|
Add-LogEntry (Start-Transcript -Path "$LogDir\$ScriptName.log" -UseMinimalHeader)
|
|
}
|
|
|
|
|
|
} |