Skip to content

Instantly share code, notes, and snippets.

@torgro
Created December 4, 2018 22:56
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 torgro/4a88ec4eb1f9f58bfd4d795ef93e2fbc to your computer and use it in GitHub Desktop.
Save torgro/4a88ec4eb1f9f58bfd4d795ef93e2fbc to your computer and use it in GitHub Desktop.
function Test-Command
{
[cmdletbinding()]
Param()
write-verbose -Message "Start"
}
function Write-Verbose
{
[cmdletbinding()]
Param(
[string]
$Message
)
$date = [datetime]::Now
$parentFunction = (Get-Variable -Name MyInvocation -Scope 1).Value.MyCommand.Name
$logFile = $env:SystemDrive |
Join-Path -ChildPath temp |
Join-Path -ChildPath log.txt
$objectLogFile = $env:SystemDrive |
Join-Path -ChildPath temp |
Join-Path -ChildPath log.json
$logThis = "$date - $message"
$logObj = [pscustomobject][ordered]@{
Date = $date
Command = $parentFunction
Message = $Message
}
Add-Content -Path $logFile -Value $logThis -Encoding UTF8
$logObj | ConvertTo-Json -Compress | Add-Content -Path $objectLogFile -Encoding UTF8
Microsoft.PowerShell.Utility\Write-Verbose -Message "$parentFunction - $Message"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment