Enumerating and filtering
Enumerating, or listing, the objects in a collection in PowerShell does not need a specialized command. For example, if the results of Get-PSDrive
were assigned to a variable, enumerating the content of the variable is as simple as writing the variable name and pressing Return, allowing the values to be viewed:
PS> $drives = Get-PSDrive
PS> $drives
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
Alias Alias
C 319.37 611.60 FileSystem C:\
Cert Certificate \
Env Environment
...
ForEach-Object
may be used to work on an existing collection or objects, or used to work on the output from another command in a pipeline.
Where-Object
may be used to filter an existing collection or objects, or it may be used to filter the output from another command in a pipeline.