Created
August 24, 2022 07:46
-
-
Save zett42/f38ce059af99d870c1591bff51244053 to your computer and use it in GitHub Desktop.
PowerShell GetSteppablePipeline
This file contains 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 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