Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit 4333568

Browse files
committed
Date and Time format parameters.
1 parent 860ae6b commit 4333568

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Write-Log.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Return the message that was passed to the function
3232
Specifies that the message is a debug message. Debug messages only get logged if -LogDebugMessage is set to $true.
3333
.PARAMETER LogDebugMessage
3434
Debug messages only get logged if this parameter is set to $true in the config XML file.
35+
.PARAMETER LogDateFormat
36+
Date format, as expected by `Get-Date -Format`. Default: 'yyyy-MM-dd'
37+
.PARAMETER LogTimeFormat
38+
Time format, as expected by `Get-Date -Format`. Default: 'HH:mm:ss.fff'
3539
.EXAMPLE
3640
Write-Log -Message "Installing patch MS15-031" -Source 'Add-Patch' -LogType 'CMTrace'
3741
.EXAMPLE
@@ -81,7 +85,11 @@ Function Write-Log {
8185
[Parameter(Mandatory=$false,Position=11)]
8286
[switch]$DebugMessage = $false,
8387
[Parameter(Mandatory=$false,Position=12)]
84-
[boolean]$LogDebugMessage = $false
88+
[boolean]$LogDebugMessage = $false,
89+
[Parameter(Mandatory=$false,Position=13)]
90+
[string]$LogDateFormat = 'yyyy-MM-dd',
91+
[Parameter(Mandatory=$false,Position=14)]
92+
[string]$LogTimeFormat = 'HH:mm:ss.fff'
8593
)
8694

8795
Begin {
@@ -111,8 +119,8 @@ Function Write-Log {
111119
}
112120

113121
# Initialize the date/time variables
114-
[string]$LogTime = (Get-Date -Format HH:mm:ss.fff).ToString()
115-
[string]$LogDate = (Get-Date -Format MM-dd-yyyy).ToString()
122+
[string]$LogTime = (Get-Date -Format $LogTimeFormat).ToString()
123+
[string]$LogDate = (Get-Date -Format $LogDateFormat).ToString()
116124
If (-not (Test-Path -Path 'variable:LogTimeZoneBias')) {
117125
[int32]$script:LogTimeZoneBias = [System.TimeZone]::CurrentTimeZone.GetUtcOffset([datetime]::Now).TotalMinutes
118126
}

0 commit comments

Comments
 (0)