I’m trying to write a very simple PowerShell script to give me the total number of items (both files and folders) in a given folder (c:\MyFolder). Here’s what I’ve done:
Write-Host ( Get-ChildItem c:\MyFolder ).Count;
The problem is, that if I have 1 or 0 items, the command does not work—it returns nothing.
Any ideas?
You should use
Measure-Objectto count things. In this case it would look like:or if that’s too long
and in PowerShell 4.0 use the
measurealias instead ofmo