How can I count all files in a specific folder (and all subfolders) with the Powershell command Get-ChildItem?
With (Get-ChildItem
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 -Recurse | Where-Object {!$_.PSIsContainer} | Measure-Object
$files.Count
In PowerShell v3 we can do the following to get files only:
Get-ChildItem -File -Recurse