How it works...

What we did in this recipe was certainly non-intuitive, considering we could use just Where-Object along with the Get-ChildItem. However, the intention of this recipe was to demonstrate the use of Group-Object. The Group-Object cmdlet creates groups based on the criteria we specify, and names the groups on the criteria. In our case, the criteria for grouping was the extension, and hence, the names of the groups were the extensions.

Each of these groups contains its elements, which are objects in themselves. If we simply want the count and the names of the groups, we use the NoElement parameter. If we want only the elements, we use the ExpandProperty parameter of the Select-Object cmdlet and expand all the elements. The elements thus expanded are the objects of the cmdlet preceding the Group-Object cmdlet (Get-ChildItem in our case).

If Where-Object and other cmdlets could do what Group-Object could in a complicated way, why have it in the first place? Read on until Taking actions on the returned objects to know more.

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

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