0

How can i only select the first row (Name) from this Output in powershell? Output

The Code is this one:

1. Import-Module "C:\CMI\Entwicklung\MetaTool\packages\psake.4.5.0\tools\psake.psm1"
2. invoke-psake -buildFile "C:\CMI\Entwicklung\MetaTool\Build\default.ps1" -docs;

I want to have only the names from this list.

Thank you!

1 Answers1

0

Pipe the Output to select-object:

Import-Module "C:\CMI\Entwicklung\MetaTool\packages\psake.4.5.0\tools\psake.psm1"
invoke-psake -buildFile "C:\CMI\Entwicklung\MetaTool\Build\default.ps1" -docs | select Name

Edit

 $a = Invoke-psake default.ps1

 $a
 psake version 4.6.0
 Copyright (c) 2010-2014 James Kovacs & Contributors

 Executing Clean
 Executed Clean!
 Executing Compile
 Executed Compile!
 Executing Test
 Executed Test!

 Build Succeeded!

 ----------------------------------------------------------------------
 Build Time Report
 ----------------------------------------------------------------------
 Name    Duration        
 ----    --------        
 Clean   00:00:00.0193100
 Compile 00:00:00.0148280
 Test    00:00:00.0169533
 Total:  00:00:00.1112917


$b=($a | select-string ":").count-1; ($a | Select-String ":")  -replace "\d{2}\:\d{2}:\d{2}.\d{7}"| select -First $b
Clean   
Compile 
Test    
Martin
  • 1,853
  • 3
  • 15
  • 22
  • assign the Output to a var and get ist type: `$a = invoke.....; $a.gettype()` This will give you an idea, what datatype that is, and if we can use select statements. – Martin Mar 30 '16 at 13:11
  • The var is a System.Array. Here are the types from each value in the Array: 1 + 2 = Microsoft.PowerShell.Commands.Internal.Format.StartData 3 - 9 = Microsoft.PowerShell.Commands.Internal.Format.PacketInfoData – Bursac Milan Mar 30 '16 at 13:23
  • Is there an easy way to get this module running in own Environment, without setting up some build process? If there is an Array, containg "Name", you shoud Access it by using $Array | select Name. Possible, that they are using write-Output Statements, but this isnt good in functions. – Martin Mar 30 '16 at 13:32
  • i will look again in the wiki... i tried a lot (select, split, Format, etc.) but nothing seems to work.. – Bursac Milan Mar 30 '16 at 13:40
  • You can also look into the function, what type they give back etc. but i assume, it is a bigger one with calls to other functions etc. – Martin Mar 30 '16 at 13:43
  • yes it calls a lot of methods.. anyway thank you for your help – Bursac Milan Mar 30 '16 at 13:53
  • another attempt: As it creates an Array of strings you could work with `select-string`: `($a | Select-String ":") Clean 00:00:00.0084516 Compile 00:00:00.0116696 Test 00:00:00.0080837 Total: 00:00:00.0407568` This will give you the rows as lines(of type string), on which you can work with `-split` – Martin Mar 30 '16 at 14:07
  • And even more improved: `$b=($a | select-string ":").count-1; ($a | Select-String ":") -replace "\d{2}\:\d{2}:\d{2}.\d{7}"| select -First $b` – Martin Mar 30 '16 at 14:16