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

要计算PowerShell中文件中的总行数,您首先需要使用Get-Content cmdlet检索项目的内容,并需要使用方法Length()来检索总行数。一个例子如下所示。

示例

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

输出结果

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