Skip to content

Instantly share code, notes, and snippets.

@vScripter
Created September 5, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vScripter/376fcc4c5c6027f9d3d6903c2e4136da to your computer and use it in GitHub Desktop.
Save vScripter/376fcc4c5c6027f9d3d6903c2e4136da to your computer and use it in GitHub Desktop.
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