Skip to content

Instantly share code, notes, and snippets.

@zett42
Created August 24, 2022 07:46
Show Gist options
  • Save zett42/f38ce059af99d870c1591bff51244053 to your computer and use it in GitHub Desktop.
Save zett42/f38ce059af99d870c1591bff51244053 to your computer and use it in GitHub Desktop.
PowerShell GetSteppablePipeline
function Write-Log {
param(
[Parameter(ValueFromPipeline, Mandatory)]
[object] $InputObject,
[parameter(Mandatory)]
[string] $Path,
[parameter()]
[switch] $PassThru
)
begin {
$scriptBlock = { Set-Content -LiteralPath $Path }
$steppablePipeline = $scriptBlock.GetSteppablePipeline( $myInvocation.CommandOrigin )
$steppablePipeline.Begin( $PSCmdlet )
}
process {
$steppablePipeline.Process( "$(Get-Date) - $InputObject" )
if($PassThru.IsPresent) { $InputObject }
}
end {
$steppablePipeline.End()
}
}
$FileList = Get-ChildItem -Path $PSScriptRoot\* -Include '*.csv', '*.xlsx' |
Write-Log -Path "$PSScriptRoot\TestLog.log" -PassThru
$FileList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment