您的问题已在评论中进行了报道,并在您更新问题时发现。在3.0之前,Get-Content
不支持-TotalCount
参数。 - 首先是-TotalCount
的别名。 Runnning 2.0我可以模拟你的问题。
PS C:\Users> get-host | Select version
Version
-------
2.0
PS C:\Users> Get-Content C:\temp\anothertext.txt -first
Get-Content : A parameter cannot be found that matches parameter name 'first'.
At line:1 char:43
+ Get-Content C:\temp\anothertext.txt -first <<<<
+ CategoryInfo : InvalidArgument: (:) [Get-Content], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand
希望文件不是太大。如果没有,那么你可以管入Select-Object
或者只是使用数组索引。
if((get-content -path $outPath3)[0] -like 'Successfully generated*')
if((get-content -path $outPath3 | Select -First 1) -like 'Successfully generated*')
这两种情况的缺点是整个文件将被读入内存中,只是放下其余部分。
你在这里问什么。有关布尔值的一般问题或者您在Get-Content中的具体问题 – Matt