Problem with pipeline parameter binding RRS feed

  • Question

  • Hello,

    I'm teaching myself PowerShell with "PowerShell in a month of lunches" book but I am having a problem with a command using pipeline parameter binding. I am trying to get a list of hotfixes for all AD computers by piping a list of AD objects with "name" property renamed to "ComputerName" so get-hotfix can match these up by property name:

    get-adcomputer -filter * | Select-Object @{l='ComputerName';e={$_.name}} | get-hotfix

    So if remove get-hotfix and pipe this into get-member, I can see the list of AD objects with the property renamed as expected, but when I run the command I only receive the hotfixes from the first computer listed and then nothing. What am I missing here? I know I can do this in a different way using parenthesis but I am curious why this command is not running as expected.


    PS C:\PSTemp> get-adcomputer -filter * | Select-Object @{l='ComputerName';e={$_.name}} | get-hotfix

    Source        Description      HotFixID      InstalledBy          InstalledOn
    ------        -----------      --------      -----------          -----------
    HYDROGEN      Update           KB2919355     TESTNET\admin
    HYDROGEN      Update           KB2919442     TESTNET\admin
    HYDROGEN      Update           KB2937220     TESTNET\admin
    HYDROGEN      Update           KB2938772     TESTNET\admin
    HYDROGEN      Update           KB2939471     TESTNET\admin
    HYDROGEN      Hotfix           KB2949621     TESTNET\admin

    • Edited by ozy242 Saturday, November 5, 2016 8:09 AM
    Saturday, November 5, 2016 8:08 AM

All replies

  • your powershell command may not get the entire list of computers because the computer name is fixed in value ComputerName, you can try with a CSV list that contains the names of computers and in your control you introduced the variable that will start browse your CSV list.

    Kind regards, 

    S'il vous plaît n'oubliez pas de "Marquer comme réponse" les réponses qui ont résolu votre problème. C'est une voie commune pour reconnaître ceux qui vous ont aidé, et rend plus facile pour les autres visiteurs de trouver plus tard la résolution. Héritier KANDOLO. http://www.rootandadmin.com/

    Saturday, November 5, 2016 9:13 AM
  • Yes - Get-HotFix has a bug.  It does not accept pipeline input.


    Saturday, November 5, 2016 9:52 AM
  • Thank you for the explanation!
    Saturday, November 5, 2016 10:52 AM
  • The help explicitly states that it accepts pipeline input and the code runs without error it just does not apply the pipeline input:

    D:\scripts> help get-hotfix -par computername

    -ComputerName [<String[]>]

        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name (FQDN) of a remote


        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of this cmdlet

        even if your computer is not configured to run remote commands.

        Required?                    false

        Position?                    named

        Default value                none

        Accept pipeline input?       true (ByPropertyName)

        Accept wildcard characters?  false


    • Proposed as answer by Hello_2018 Tuesday, November 15, 2016 9:22 AM
    Saturday, November 5, 2016 9:35 PM
  • ByPropertyName is all that is required:

    D:\scripts> function test{
    >> Param(
    >> [Parameter(ValueFromPipelineByPropertyName)]
    >> $ComputerName
    >> )
    >> $PSBoundParameters
    >> }
    D:\scripts> $p = [pscustomobject]@{ComputerName = 'Somename'}
    D:\scripts> $p | test
    Key          Value
    ---          -----
    ComputerName Somename
    D:\scripts> help test  -par ComputerName
    -ComputerName <Object>
        Required?                    false
        Position?                    0
        Accept pipeline input?       true (ByPropertyName)
        Parameter set name           (All)
        Aliases                      None
        Dynamic?                     false


    Saturday, November 5, 2016 9:54 PM
  • D:\scripts> [array]$p += [pscustomobject]@{ComputerName = 'Tom'}
    D:\scripts> $p += [pscustomobject]@{ ComputerName = 'Dick' }
    D:\scripts> $p += [pscustomobject]@{ ComputerName = 'Harry' }
    D:\scripts> $p | test


    Saturday, November 5, 2016 10:20 PM