Script blocks not working

Hello All, I’m now getting the basics with powershell and i’m watching Powershell Jumpstart on MVA.
On the part “The Pipeline : Deeper” Jeffrey gave an example of using the pipeline. with called script-parameters. it looks very cool but I cant get this to work.
The command is :
get-ADComputer - filter * |get-wmiobject win32_bios -computername {$_.name}

I believe the command works as follow: get-adcomputers is pushing everything to the pipeline and the parameter {$_.name} grabs the value and use it on the -computername property.

Did Jeffrey use a wrong example or do I something wrong?

That script block syntax only works for parameters that accept pipeline input (either by value or by property name, doesn’t matter). In this case, Get-WmiObject’s -ComputerName parameter doesn’t accept pipeline input.

You can still use ForEach-Object, though:

get-ADComputer – filter * | ForEach-Object { get-wmiobject win32_bios -computername $_.name }

There is a space between the hypen and Filter parameter (- Filter), it should be -Filter. Get-AD* cmdlets return a non-standard PSObject with Microsoft.ActiveDirectory.Management.XXXX. If you do:

Get-ADComputer –Filter * | Select Name | Get-WMIObject -Class Win32_BIOS -ComputerName {$_.Name}

It should correct the issue if the space in the parameter wasn’t your issue. Select-Object generates a new PSObject with the properties you tell it get, so the $_.Name reference will work as expected. It’s just something quirky specifically with the AD cmdlets. Also, note that you are trying to run an AD command for EVERY computer in AD. You can do a small amount of computers or a single computer:

Get-ADComputer –Filter "Name -eq 'Computer123'" | Select Name | Get-WMIObject -Class Win32_BIOS -ComputerName {$_.Name}

or

#Find all computers that start with CMP
Get-ADComputer –Filter "Name -like 'CMP*'" | Select Name | Get-WMIObject -Class Win32_BIOS -ComputerName {$_.Name}

I’ll get it now. Thanks
Indeed get-wmiobject does not accept pipeline input. (by default). But with those commands you can grab “Name” and put it in get-wmiobject cmdlet.
I use the GET-ADcomputer in a small environment (Hyper-v lab with 10 vm’s) so the output doesn’t generate a lot of data.