Created
September 5, 2017 18:29
-
-
Save vScripter/376fcc4c5c6027f9d3d6903c2e4136da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROCESS { | |
if (Test-Path -LiteralPath $filePath) { | |
if ($Indent) { | |
$indentMessage = $(Add-Indent -Level $Indent) + $Message | |
Write-Verbose -Message 'Adding message to Work Log' | |
Write-Output -InputObject $indentMessage | Out-File $filePath -Append | |
} else { | |
Write-Verbose -Message 'Adding message to Work Log' | |
Write-Output -InputObject "* $Message" | Out-File $filePath -Append | |
} # end if/else $Indent | |
} elseif (-not (Test-Path -LiteralPath $filePath)) { | |
Write-Warning -Message 'Work log not created' | |
try { | |
Write-Verbose -Message 'Creating worklog file' | |
New-Item -Path $filePath -Type File -ErrorAction 'Stop' | Out-Null | |
if ($Indent) { | |
Write-Warning -Message "Since the file has not be created, your '-Indent' input of '$Indent' will be ignored for the first log entry." | |
} # end if $Indent | |
Write-Verbose -Message 'Adding message to Work Log' | |
Write-Output -InputObject '## Work Log ' | Out-File -LiteralPath $filePath -Append | |
Write-Output -InputObject "### $nowLong" | Out-File -LiteralPath $filePath -Append | |
Write-Output -InputObject ' ' | Out-File -LiteralPath $filePath -Append | |
Write-Output -InputObject "* $Message" | Out-File -LiteralPath $filePath -Append | |
if (Test-Path -LiteralPath $filePath -PathType Leaf) { | |
Write-Verbose -Message 'Work Log file created successfully' | |
} else { | |
Write-Verbose -Message 'Work Log file not created' | |
} # end if/else | |
} catch { | |
Write-Warning -Message "Error creating work log file. $_" | |
} # end try/catch | |
} # end if/elseif | |
} # end PROCESS block |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment