Let me preface this by saying I'm completely new to Powershell and I'm not too familiar with the language.
I'm looking to create a simple script that will count the lines of a text file and then return the result as an integer. This is the code I have so far:
$lines = Get-Content -Path "C:\File" | Measure-Object -Line
and it returns the following:
Lines Words Characters Property
----- ----- ---------- --------
8
However, I'm looking to return the 8 as a single integer so it can be stored as a variable. Is there an easy way to do this? I appreciate any help.
Thank you!
You can use the . operator like this:
(Get-Content -Path "C:\File" | Measure-Object -Line).Lines
What you had earlier was basically an object with 4 properties: "Lines", "Words", "Characters", and "Property". Using . is an easy way to access such properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With