Created
December 4, 2018 22:56
-
-
Save torgro/4a88ec4eb1f9f58bfd4d795ef93e2fbc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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