简体   繁体   English

仅从Powershell中的TF.exe返回Label属性

[英]Only return Label property from TF.exe in Powershell

I am running this command in Powershell 我在Powershell中运行此命令

.\TF.exe labels /owner:* BLD_NUM_1*

This produces a result which looks like 这样产生的结果看起来像

Label     Owner     Date
-------------------------
Label1    MyOwner   2016-07-08
Label2    MyOwner   2016-07-11

I want to only return the Label property, so I have tried this 我只想返回Label属性,所以我尝试了

.\TF.exe labels /owner:* BLD_NUM_1* | Select-Object -Property Label

However this just outputs 但是,这只是输出

Label
-----

And no data. 而且没有数据。

I have also tried 我也尝试过

.\TF.exe labels /owner:* BLD_NUM_1* | select Label

and the output is the same. 和输出是相同的。

Working with executable that output string data can be a pain, especially when they have labels and other formatting around their data. 使用输出字符串数据的可执行文件可能会很痛苦,尤其是当它们在数据周围具有标签和其他格式时。 in this case since you need to skip the first few lines it's probably easiest to use a FOR loop to iterate over the array and parse the data out of each string. 在这种情况下,由于您需要跳过前几行,因此使用FOR循环遍历数组并从每个字符串中解析出数据可能是最简单的。 The function below will take the results of TF.exe and give you the just the contents of the "label" line. 下面的函数将获取TF.exe的结果,并为您提供“标签”行的内容。 note that it will only work if there are no spaces in any of the labels, if there are you'll need to work out another way to parse the string. 请注意,只有在任何标签中都没有空格的情况下,它才会起作用,如果有空格,则需要解决另一种解析字符串的方法。

Function Get-TFResults {
  $TFresult = .\TF.exe labels /owner:* BLD_NUM_1*
  for($i=2; $i -le $TFresult.Count - 1; $i++){
    $TFresult[$i].substring(0,($TFresult[$i].indexof(" ") - 1))
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM