Count items in a folder with PowerShell

后端 未结 7 1358
闹比i
闹比i 2020-12-01 04:10

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 wh

7条回答
  •  旧巷少年郎
    2020-12-01 04:33

    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 | mo).Count;
    

    and in PowerShell 4.0 use the measure alias instead of mo

    Write-Host (dir c:\MyFolder | measure).Count;
    

提交回复
热议问题