Welcome Forums General PowerShell Q&A Validation

This topic contains 2 replies, has 3 voices, and was last updated by

4 years, 2 months ago.

  • Author
  • #21577

    Points: 0
    Rank: Member

    Hi Team,
    Could you please tell me how can I get to know how the input has been given? what I mean is...

    1. by .txt file
    gc input.txt | %{Verb-Noun $_}
    2. or CSV file
    Import-Csv input.csv | %{Verb-Noun $_.input}
    3. or direct input to the parameter?
    Verb-Noun -InputParam "InputItem"

  • #21582

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    From within the command "Verb-Noun," the input on 1 and 2 arrives from the pipeline. You don't know how the data got into the pipeline, and you can't know.

    For 3, input was provided directly to a parameter. You could use the $PSBoundParameters collection.

    In many cases, if you write your function correctly, it doesn't matter where the input came from.

  • #21611

    Points: 0
    Rank: Member

    In this particular case, as far as your Verb-Noun function is concerned, all three examples are "direct input to the parameter". The first two examples happen to be using positional binding instead fo a named parameter, but either way, you're not actually piping input to Verb-Noun. You're piping it to ForEach-Object, and then calling Verb-Noun multiple times from there.

    While you 'might' be able to pull the information you're asking about from either $MyInvocation or Get-PSCallStack, your Verb-Noun command really shouldn't care where the input comes from, and trying to figure that out from inside Verb-Noun will seriously clutter your code. I'd be asking myself why I felt I needed that information in the first place, and see if I can find some other approach.

The topic ‘Validation’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort