How to do it...

To group objects based on a property, we use the Get-ChildItem cmdlet on the files that we created for use in this book.

  1. Navigate to the location where you created or downloaded the files.
PS> Set-Location ~/random
  1. List out only the files (exclude the directories).
PS> Get-ChildItem -Path . -File

Or use the shorthand version.

PS> gci -File
  1. Group the objects based on the extension.
PS> Get-ChildItem . -File | Group-Object Extension
  1. The shorthand version of this would be:
PS> gci -File | group Extension
  1. Use the Select-Object cmdlet to only show the extension and the number of files in each extension.
PS> Get-ChildItem -Path . -File | Group-Object -Property Extension | Select-Object -Property Name, Count
  1. Is there a simpler way to do this?
PS> Get-ChildItem -Path . -File | Group-Object -Property Extension -NoElement
  1. Now that we know how to handle grouping and expanded property selection, let us pick only the JPG files from the lot.
PS> Get-ChildItem -Path . -File | Group-Object -Property Extension | Where-Object Name -EQ .jpg | Select-Object -ExpandProperty Group
..................Content has been hidden....................

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