如何在 PowerShell 中统计文件的总行数?

powershellmicrosoft technologiessoftware & coding更新于 2026/2/14 22:37:17

要在 PowerShell 中统计文件的总行数,首先需要使用 Get-Content cmdlet 检索项目内容,然后使用方法 Length() 检索总行数。示例如下。

示例

(Get-Content D:\Temp\PowerShellcommands.csv).Length

输出

PS C:\WINDOWS\system32> (Get-Content D:\Temp\PowerShellcommands.csv).Length
5727

相关文章