Skip to content

Commit

Permalink
Starting a shared function to write to a log
Browse files Browse the repository at this point in the history
  • Loading branch information
SamErde committed Jun 27, 2024
1 parent ce3ce65 commit f849118
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Script Logging/Write-Log.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Write-Log {
# Write a string of text to the host and a log file simultaneously.
[CmdletBinding()]
[OutputType([string])]
param (
# The message to display and write to a log
[Parameter(Mandatory)]
[string]
$LogText,

# Type of output to send
[Parameter()]
[ValidateSet('Both','HostOnly','LogOnly')]
[string]
$Output = 'Both'
)

switch ($Output) {
Both {
Write-Host "$LogText"
[void]$LogStringBuilder.AppendLine($LogText)
}
HostOnly {
Write-Host "$LogText"
}
LogOnly {
[void]$LogStringBuilder.AppendLine($LogText)
}
}
} # end function Write-Log

0 comments on commit f849118

Please sign in to comment.