by Pat Richard at 2012-09-16 11:11:53
So I’m good on setting a function up to use parameters via a param block. And I think I’ve got it covered for using code blocks to support pipeline input. But what if I want to support both? I have a function that supports pipeline input:by RichardSiddaway at 2012-09-17 01:15:56function New-SignedScript{
Begin{
$cert = @(Get-ChildItem cert:\currentuser\my -codesigning)[0]
if (!($cert).NotAfter -gt (Get-Date)){
Write-Error "No valid codesigning certificate found"
break
}
}
Process{
Set-AuthenticodeSignature $_ $cert | Out-Null
}
End{}
}
And I can do something like:Get-Item test*.ps1 | New-SignedScript
with success. But I’m looking to also support something like:New-SignedScript test.ps1
to support single files.
Try thisfunction mydemo {
[CmdletBinding()]
param (
[parameter(ValueFromPipelineByPropertyName=$true,
ValueFromPipeline=$true )]
[string]$path
)
PROCESS {
Get-ChildItem -Path $path
}
}
"pipeline"
"c:\scripts" | mydemo
"parameter"
mydemo -path "c]
check out the help files for advanced functions
get-help about_functions*