Powershell: Count items in a folder with PowerShell
You should use Measure-Object to count things. In this case it would look like: Write-Host ( Get-ChildItem c:\MyFolder | Measure-Object ).Count; or if that’s too long Write-Host ( dir c:\MyFolder | measure).Count; and in PowerShell 4.0 use the measure alias instead of mo Write-Host (dir c:\MyFolder | measure).Count;