Fixing the Pipeline

Some comments to support Module 3 of course M10961

# The following command will not work as Get-ADComputer returns ADComputer

# objects which can not bind to any parameter of Get-Service

Get-ADComputer -Filter * | Get-Service -Name BITS

# One alternative is to use ForEach-Object but this tends to be processor intensive

Get-ADComputer -Filter * | ForEach-Object {Get-Service -Name BITS -ComputerName $_.name}

# Another option is to modify the object in the pipeline so it has the properties we need

Get-ADComputer -Filter * | Select *,@{Name=“ComputerName”;Expression={$_.name}} | Get-Service -Name BITS

# Or you can use parathentical commands

Get-Service -Name BITS -ComputerName (Get-ADComputer -Filter * | Select -ExpandProperty Name)

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *