Pipeline Parameter by PropertyName

I must be doing something wrong. Hopefully someone can help. When I try to pass the -computername parameter for Get-HotFix it only returns the local machine, but works when I use it in paranthesis for the parameter. BTW, this is from a Month of Lunches Lab (chapter 9). According to the help for Get-Hotfix, the computername parameter should work as pipeline input by PropertyName.

 

get-adcomputer -filter * | select @{n='computername';e={$_.name}} | Get-HotFix
#This only returns objects for the domain controller (local machine)

Get-HotFix -ComputerName (select -ExpandProperty name)
#This works and returns objects for all the computers on the domain

 

 

I’m kinda new to PowerShell but in line one if you are passing a variable “computername” it should have a $ in front and also in double quotes “” instead of single quotes to allow it to use what is stored.

 

Hope this helps.

Are you sure on
<pre
Get-HotFix -ComputerName (select -ExpandProperty name)
</pre

Looks like a bug. I can’t get the second method to work either.

Are you sure on

Get-HotFix -ComputerName (select -ExpandProperty name)

My bad I’m working from an offline lab environment so I can’t copy and paste. The second line that works is this:

Get-HotFix -ComputerName (get-adcomputer -filter * | select -ExpandProperty name)

I’m using PSVersion 4.0 and Server 2012 with activedirectory module imported.

Oh, I see. There’s already comments on this doc that piping in computername doesn’t work: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-hotfix?view=powershell-5.1

Theoretically this should work too, but it doesn’t:

get-adcomputer -filter * | Get-HotFix -computername { $_.name } 

-ComputerName parameter in Get-HotFix takes value from pipeline only in documentation, Actually it doesn’t.
It just iterates through the list of computers specified to ComputerName.

The parameter is just defined like ValueFromPipelineByPropertyName = true

yourself can check it from the source code here. It doesn’t even have a ProcessRecord() method.

just filed an issue on it.

That’s actually right. It’s a hash table to make a custom property with select-object.

PS C:\users\superuser> get-process chrome | select-object @{n='myname';e={$_.name}}

myname
------
chrome