Problem accepting pipeline input byPropertyName

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 (Problem with pipeline parameter binding), 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

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.

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.

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.

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?

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

https://powershell.org/forums/topic/custom-properties-and-piping/#post-12964

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

Appreciated!