0206 | The pipeline - Deeper
How the pipeline really works | The 4 step solution
1 | ByValue
| match by value
- example
# match by -InputObject <ServiceController[]>
# (ByValue)
get-service | stop-service -whatif - the object types must match
- first, check what kind of objects are going through the pipeline
<command> | get-member
- then check the receiving commands parameters
get-help <recevi-command> -full
- accepting pipeline input? --> true (
ByValue
) AND object type match
2 | ByPropertyName
| match by propertyname
- name of the property coming across must match the name of the property on the receiving end
- example
# ByPropertyName
# -Name <String[]> -- Name -> Name
get-service | stop-process -whatif
# ByPropertyName
# -Path
get-process calc | dir
3 | What if my property doesn't match | Customize it!
- if the propertynames do not match, fix them in flight
- example
# get all the computer names and check for the bits service on each of them
# ByPropertyName: Name <-> ByPropertyName: ComputerName <String[]>
get-adcomputer -filter * | get-service -name bits
# fix with customcolumns/calculated properties
get-adcomputer -filter * | select -property name, @{name='ComputerName';expression={$_.name}}
# or the same as
get-adcomputer -fileter * | select -property name, @{n='NewName';e={$_.name}}
# or
get-adcomputer -fileter * | select -property name, @{label='NewName';e={$_.name}}
# or
get-adcomputer -fileter * | select -property name, @{l='NewName';e={$_.name}}
# and then leave the "name" column out
get-adcomputer -filter * | select -property @{name='ComputerName';expression={$_.name}}
# finally -- pass it through
get-adcomputer -filter * | select -property @{n='ComputerName';e={$_.name}} | get-service -name bits
4 | The Parenthetical | When all else fails
- no match by value, by propertyname and no renaming will fix it
- only by string, no objects
- example
# -computername expects string computernames --> select only by the name AND conv to string
get-wmiobject -class win32_bios -computername (get-adcomputer -filter * | select -expandproperty name)
# or since PSv3
get-wmiobject -class win32_bios -computername (get-adcomputer -filter * ).name
# or use get-ciminstance instead of get-wmiobject
get-help get-ciminstance
# or with script blocks
get-adcomputer -filter * | get-wmiobject -class win32_bios -computername {$_.Name}