Problem accepting pipeline input byPropertyName

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of Longjohn Longjohn 1 month ago.

  • Author
    Posts
  • #64954
    Profile photo of Longjohn
    Longjohn
    Participant

    I'm running through some lab questions in Posh MOL 3rd Edition, and specifically trying to get the following command to work. All that happens is it grabs the hotfixes on my local machine;

    get-adcomputer -Filter * | select -Property @{n='computername';e={$_.name}} | get-hotfix

    Get-hotfix's help says it accepts a "computername" parameter from pipeline byPropertyName, yet my command above fails to give me the list of hotfixes for each computer, as I'd expect. what gives?

    I am on a domain, and I can contact the adcomputers. Furthermore, backing up a step to the pipeline preceding "get-hotfix", the .count() method shows me that I have 233 objects (of type adcomputer) in the pipeline. So it's something to do with how get-hotfix is handling multiple objects (I think?).

    I just don't get it, and the computername parameter definitely accepts an array too.

    NB: I noticed somebody else ran into this (https://social.technet.microsoft.com/Forums/en-US/93b1ce4b-5e78-4129-9e09-c953019adf6f/problem-with-pipeline-parameter-binding?forum=winserverpowershell), but the article doesn't really give a definitive answer which I can tell.

    I'm either completely misunderstanding how the pipeline process works, or there's something else at play here.

    Really hoping somebody will be able to help me find an answer.

    Many thanks

  • #64977
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    You can help Get-Hotfix to determine what parameterset you want to use by specifying the paramter name ....
    Try this:

    Get-HotFix -ComputerName $(Get-ADComputer -Filter * |  select -ExpandProperty name )

    But this could take a while and could throw some errors when some of the computers are not available.

    • #64980
      Profile photo of Longjohn
      Longjohn
      Participant

      Thanks Olaf, but unfortunately the lab question specified not to use parenthesis; rather it should use the pipeline. Furthermore, as stated, the help for get-hotfix clearly states that the computername parameter accepts pipeline input byPropertyName. Multiple objects (arrays) allowed too.

      I need to know that I'm understanding the pipeline properly, and that it works as expected.

  • #65026
    Profile photo of Dudebro
    Dudebro
    Participant

    Is it a bug? If not, I don't understand it. With Stop-Process, another cmdlet that takes pipeline input by property, I can pass an object or a collection of objects with a "Name" property.

    @(
        [PSCustomObject] @{ Name = "Process1" }
        [PSCustomObject] @{ Name = "Process2" }
        [PSCustomObject] @{ Name = "Process3" }
    ) | Stop-Process
    

    This works, but trying a similar approach with Get-HotFix doesn't (at least in PowerShell 4.0).

    @(
        [PSCustomObject] @{ ComputerName = "COMPUTER1" }
        [PSCustomObject] @{ ComputerName = "COMPUTER2" }
        [PSCustomObject] @{ ComputerName = "COMPUTER3" }
    ) | Get-HotFix
    

    The command runs with no errors, but instead of processing the objects it seems to return results for the local computer instead.

    • #65031
      Profile photo of Longjohn
      Longjohn
      Participant

      Hey @dudebro. Many thanks for the reply.

      I think it might well be. However, the reason I was questioning myself was the fact that it was in one of the Lab questions for Powershell in a Month of Lunches 3rd Edition, and confirmed as valid.

      Ex: Get-ADComputer -filter * | Select-Object @{l='computername';e={$_.name}} | Get-Hotfix

      I too am able to get this working with process objects and creating an aduser(s), in-line with your example methods; just not when piping to the get-hotfix cmdlet.

      Whilst I think it must be a bug, it would be good to get one of the authors' view on it, just to confirm either way.

      Are you seeing this @DonJones / @jeffhicks?

  • #65053
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    @Longjohn, see Don Jones' @donj reply to same topic on a different post.

    • #65088
      Profile photo of Longjohn
      Longjohn
      Participant

      @curtissmith Many thanks for pointing this out. I'll be sure to search the forum first next time 😉

      Appreciated!

You must be logged in to reply to this topic.