Supporting both pipeline and parameter input

Welcome Forums General PowerShell Q&A Supporting both pipeline and parameter input

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5116

    Points: 0
    Rank: Member

    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*

The topic ‘Supporting both pipeline and parameter input’ is closed to new replies.