Skip to content

Instantly share code, notes, and snippets.

@rbleattler
Created February 18, 2021 14:57
Show Gist options
  • Save rbleattler/cb861e2cd0d5dd941e4c2e19abc7e822 to your computer and use it in GitHub Desktop.
Save rbleattler/cb861e2cd0d5dd941e4c2e19abc7e822 to your computer and use it in GitHub Desktop.
PowerShell Write Verbose with Timestamp Parameter
function Write-Verbose {
[CmdletBinding()]
Param(
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[string]
$Message,
[Parameter()]
[switch]
$TimeStamp
)
begin {
Write-Debug "Enter [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
$PSBoundParameters.Keys.ForEach{
if ($PSBoundParameters.PSItem -is [string]) {
Write-Debug "$_ : $($PSBoundParameters.Item($_))"
} else {
Write-Debug "$_ : $($PSBoundParameters.Item($_).GetType())"
}
}
}
process {
if ($TimeStamp) {
$Message = '[{0} : {1}]' -f $(Get-Date -Format G), $Message
}
[System.Management.Automation.VerboseRecord]::new($Message)
}
end {
Write-Debug "Exit [$($PSCmdlet.MyInvocation.MyCommand.Name)]..."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment