Powershell pipeline where does not behave as expected

When I use a filter to exclude an object using a pipeline command, it does not give me the correct output.

PS C:\Users\Administrator> $proall = Get-ADComputer -filter * | ? {$_.name -ne "adfs"} | select @{l='Computername';e={$_
.name}} | ps | select machinename,processname,id | sort id | ft -au

MachineName ProcessName                             Id
----------- -----------                             --
DC          Idle                                     0
DC          Idle                                     0
DC          Idle                                     0
DC          System                                   4
DC          System                                   4
DC          System                                   4
DC          mmc                                     96
DC          mmc                                     96
DC          mmc                                     96
DC          smss                                   276
DC          smss                                   276
DC          smss                                   276
DC          svchost                                304
DC          svchost                                304
DC          svchost                                304

So here it is not. the processes that we see are more than the actual ones. processes on the machine. However, there are no specific processes (exchange and sharepoint) from another machine.


To test my team, I ensured that the next output would be as expected.

PS C:\Users\Administrator> Get-ADComputer -filter * | ? {$_.name -ne "adfs"} | select @{l='Computername';e={$_.name}}

Computername
------------
DC
SP2013
EX2013

and

Get-ADComputer -filter * | ? {$_.name -eq "sp2013"} | select @{l='Computername';e={$_.name}} | get-process

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     96       9     1664      11264    94            2712 conhost
     94       9     1608      11004    95            5792 conhost
    326      15     1484       4032    56             392 csrss

I guaranteed that the above process is specific to the computer specified in the filter '?' / 'Where'.

The problem is that I am excluding a specific object.

I would like to know why he behaves in this way. I am not looking for a result, but trying to understand the syntax.

Hello

EDIT: . 3 ( ); 3.

+4
2

..... .

PowerShell 4.0 , . , .

Get-ADComputer -filter '*' | 
    ? {$_.name -ne "adfs"} | 
    select @{l='Computername';e={$_.name}} | 
    %{ ps -ComputerName $_.Computername} |
    select machinename,processname,id | sort id | ft -au

, . trace-command , , , | ps. $computers - . .

Trace-Command -Name ParameterBinding -Expression {$computers | ps} -PSHost

, , . , , ps .

, .


, . , , . . , , , . . , .

+3

, , ps , .

:

Get-ADComputer -filter * | ? {$_.name -ne "adfs"} | foreach-object{ ps -computername $_.name| select machinename,processname,id | sort id} |
0
source

Source: https://habr.com/ru/post/1616618/


All Articles