Created
March 21, 2018 21:38
-
-
Save lzybkr/9baf5f57fc4470bcf82097796c88d771 to your computer and use it in GitHub Desktop.
Quick and dirty timestamp on output
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 Out-Default | |
{ | |
[CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')] | |
param( | |
[switch] | |
${Transcript}, | |
[Parameter(ValueFromPipeline=$true)] | |
[psobject] | |
${InputObject}) | |
begin | |
{ | |
try { | |
$outBuffer = $null | |
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) | |
{ | |
$PSBoundParameters['OutBuffer'] = 1 | |
} | |
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Out-Default', [System.Management.Automation.CommandTypes]::Cmdlet) | |
$scriptCmd = { & $wrappedCmd @PSBoundParameters } | |
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) | |
$steppablePipeline.Begin($PSCmdlet) | |
} catch { | |
throw | |
} | |
} | |
process | |
{ | |
try { | |
Write-Host -NoNewLine "$([datetime]::now.ToString()): " | |
$steppablePipeline.Process($_) | |
} catch { | |
throw | |
} | |
} | |
end | |
{ | |
try { | |
$steppablePipeline.End() | |
} catch { | |
throw | |
} | |
} | |
<# | |
.ForwardHelpTargetName Microsoft.PowerShell.Core\Out-Default | |
.ForwardHelpCategory Cmdlet | |
#> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment