Skip to content

Instantly share code, notes, and snippets.

@ashdar
Created February 22, 2019 15:19
Show Gist options
  • Save ashdar/a9256d2ea130c48113eeb1fb913d8cea to your computer and use it in GitHub Desktop.
Save ashdar/a9256d2ea130c48113eeb1fb913d8cea to your computer and use it in GitHub Desktop.

Revisions

  1. ashdar created this gist Feb 22, 2019.
    39 changes: 39 additions & 0 deletions SimpleArrayAndPipelineInputDemo.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    function foo {
    [cmdletbinding()]
    param (
    [Parameter(Mandatory = $true,
    ValueFromPipeline=$True,
    ValueFromPipelineByPropertyName=$True
    )]
    [string[]] $DestinationDatabase,
    $TestName
    )

    begin {
    $i = [int] 1
    }


    process {
    foreach ($DestinationDb in $DestinationDatabase) {
    [pscustomobject] @{ID = $i; DestinationDatabase = $DestinationDb; TestName = $TestName}
    $i++
    }
    }

    }


    $stringPiped = 'justastring-piped'
    $stringPassed = 'justastring-passed'
    $arrayPiped = @('bar-array-piped','hello-array-piped','world-array-piped')
    $arrayPassed = @('bar-array-passed','hello-array-passed','world-array-passed')


    foo -DestinationDatabase $arrayPassed -TestName 'An array of 3 objects, passed as a parameter'
    $arrayPiped | foo -TestName 'An array of 3 objects, piped'

    foo -DestinationDatabase $stringPassed -TestName 'A simple string, passed as a parameter'
    $stringPiped | foo -TestName 'A simple string, piped'

    [pscustomobject] @{ID = 99; DestinationDatabase = 'pscustomobjet-NameByPipeline'} | foo -TestName 'A complex object, piped'