Measure-Object
はTextMeasureInfo
オブジェクトを返し、ない整数:
PS C:\> $lines = Get-Content .\foo.txt | Measure-Object -Line
PS C:\> $lines.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False TextMeasureInfo Microsoft.PowerShell.Commands.MeasureInfo
使用したい情報が0で提供されますそのオブジェクトのプロパティ:
PS C:\> $lines | Get-Member
TypeName: Microsoft.PowerShell.Commands.TextMeasureInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Characters Property System.Nullable`1[[System.Int32, mscorlib, Vers...
Lines Property System.Nullable`1[[System.Int32, mscorlib, Vers...
Property Property System.String Property {get;set;}
Words Property System.Nullable`1[[System.Int32, mscorlib, Vers...
プロパティは、実際の整数を返すこと:
PS C:\> $lines.Lines.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Int32 System.ValueType
PS C:\> $lines.Lines
5
ので、あなたのループ内でそれを使用することができます:それは価値がある何のため
PS C:\> for ($i = 0; $i -le $lines.Lines; $i++) { echo $i }
0
1
2
3
4
5
PS C:\> _
「Lines」プロパティには、空でない行(つまり、長さ> 0の行)の数が含まれているようです。しかし、ドキュメンテーションはこれについて言及していない。 –