简体   繁体   中英

Only return Label property from TF.exe in Powershell

I am running this command in 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

.\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. The function below will take the results of TF.exe and give you the just the contents of the "label" line. 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))
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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