concept input in category powershell

appears as: input, input, inputs
Learn PowerShell Scripting in a Month of Lunches

This is an excerpt from Manning's book Learn PowerShell Scripting in a Month of Lunches.

  • Objects are output and placed into the PowerShell pipeline, which ferries the objects to the next command in the pipeline. Commands therefore need to, in many cases, accept input from the pipeline, so that they can work in this execution model. You can continue this process for as long as you need. But realize that objects may change in the pipeline depending on what cmdlets you’re using.
  • PS C:\> "frances" | set-foo
    set-foo : The input object cannot be bound to any parameters for the
    command either because the command does not take
    pipeline input or the input and its properties do not match any of the
    parameters that take pipeline input.
    At line:1 char:13
    + "frances" | set-foo
    +             ~~~~~~~
        + CategoryInfo          : InvalidArgument: (frances:String) [Set-Foo],
    ParameterBindingException
        + FullyQualifiedErrorId : InputObjectNotBound,Set-Foo
    PowerShell in Depth, Second Edition

    This is an excerpt from Manning's book PowerShell in Depth, Second Edition.

    The problem is, Get-ADComputer produces objects of the type Computer, whereas the -ComputerName parameter wants input of the type String (it says so in the command’s help file). So that won’t work. Instead, you need to extract only the contents of the Name property from those computers, and that’s where the –ExpandProperty parameter comes in:

    PS C:\> $rx | get-member
    
       TypeName: System.Text.RegularExpressions.Regex
    
    Name                MemberType Definition
    ----                ---------- ----------
    Equals              Method     bool Equals(System.Object obj)
    GetGroupNames       Method     string[] GetGroupNames()
    GetGroupNumbers     Method     int[] GetGroupNumbers()
    GetHashCode         Method     int GetHashCode()
    GetType             Method     type GetType()
    GroupNameFromNumber Method     string GroupNameFromNumber(int i)
    GroupNumberFromName Method     int GroupNumberFromName(string name)
    IsMatch             Method     bool IsMatch(string input), bool IsMatch(...
    Match               Method     System.Text.RegularExpressions.Match Matc...
    Matches             Method     System.Text.RegularExpressions.MatchColle...
    Replace             Method     string Replace(string input, string repla...
    Split               Method     string[] Split(string input), string[] Sp...
    ToString            Method     string ToString()
    Options             Property   System.Text.RegularExpressions.RegexOptio...
    RightToLeft         Property   System.Boolean RightToLeft {get;}

    You’ll see many scripts that prompt the user for input. Don’t follow that pattern. As you’ll see, using parameters gives the best overall experience.

    PowerShell Deep Dives

    This is an excerpt from Manning's book PowerShell Deep Dives.

    Create a new CIM session using the New-CimSession cmdlet. Supply one or more computer names to be part of the session. Then use the session variable with the –CimSession parameter. When you create a CIM session you can give it a name, but you can’t use the name as input to the –CimSession parameter!

    The advantage of the mandatory parameter attribute is that it prompts users for input and even offers limited help about what the input should be. The disadvantage is that

    Figure 1. Prayer-based parsing of the input at the left produces the output at the right. The prayer is unanswered in the second series, leading to incorrect output.