Supporting both pipeline and parameter input

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:
function New-SignedScript{
$cert = @(Get-ChildItem cert:\currentuser\my -codesigning)[0]
if (!($cert).NotAfter -gt (Get-Date)){
Write-Error “No valid codesigning certificate found”
Set-AuthenticodeSignature $_ $cert | Out-Null

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.
by RichardSiddaway at 2012-09-17 01:15:56
Try this
function mydemo {
param (
ValueFromPipeline=$true )]
Get-ChildItem -Path $path


“c:\scripts” | mydemo

mydemo -path "c]

check out the help files for advanced functions
get-help about_functions*