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:

PS> $drives = Get-PSDrive
$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 where something complex needs to be done to each object.

Where-Object may be used to filter results.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.96.94