I've been trying to learn PowerShell and am currently looking at piping the output of one command into the input of another. I've found that some commands can operate on an array of items that are piped in while other commands can only operate on a single item in an array.

For example, `Where-Object` can operate on an array of items, returning a subset of them, whereas `New-Item` can only operate on a single item.

I have to handle the two types of commands differently, with commands that can only operate on a single item having to be enclosed in a `ForEach-Object` block.

For intance, `Where-Object` doesn't need a `ForEach-Object`:

```
Get-Service | where Status -eq "Stopped"

```

But `New-Item` does:

```
@("Red", "Blue", "Green") | foreach {new-item -Name $_ -ItemType directory}

```

How can I determine whether a particular command can act on an array of items, or whether it can only act on a single item? 

As far as I can see the help doesn't really give a clue. For example the help for `Where-Object` states the input type is `System.Management.Automation.PSObject`, which doesn't imply to me it can be an array of objects.

**EDIT:** aljodAv has pointed out in his answer that `ForEach-Object` is not actually needed in the second example. It can be written as:

```
@("Red", "Blue", "Green") | new-item -Name {$_} -ItemType directory

```

The question still stands, however, as $\_ represents the current item from the collection object passed through the pipeline.