Sam
Sam

Reputation: 325

Why won't my script run?

I've built the following PowerShell script and it doesn't seem to work:

"\\example\examplepath\" | % { $_ | select name, @{n="lines"; e={ get-content
$_.FullName | measure-object -line | Select -expand lines  }  } } | ft -
Autosize | Out-file c:\counts\result.csv

The script is supposed to get a line count for each file and output them to a CSV. Admittedly there around 140,000 files in the folder. Any ideas?

Upvotes: 2

Views: 42

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

You are missing the Get-ChildItem cmdlet to retrieve all files. The Foreach-Object (%) cmdlet is obsolete here so I removed it. I also removed the Format-Table cmdlet because you are piping the result to Out-File:

Get-ChildItem "\\example\examplepath\" |
     Select-Object name, @{n="lines"; e={ get-content $_.FullName | measure-object -line | Select-Object -expand lines  }  } |
     Out-file c:\counts\result.csv

Upvotes: 3

Related Questions