How can I count all files in a specific folder (and all subfolders) with the Powershell command Get-ChildItem?
With (Get-ChildItem
Filter for files before counting:
(Get-ChildItem <Folder> -recurse | where-object {-not ($_.PSIsContainer)}).Count
I would pipe the result to the Measure-Object
cmdlet. Using (...).Count can yield nothing in case there are no objects that match your criteria.
$files = Get-ChildItem <Folder> -Recurse | Where-Object {!$_.PSIsContainer} | Measure-Object
$files.Count
In PowerShell v3 we can do the following to get files only:
Get-ChildItem <Folder> -File -Recurse