none
Combine multiple outputs RRS feed

  • Question

  • Hi Guys, need some guidance here...

    I have the following variables/data:

    PS C:\> $mStream
    Stream(01)
    Stream(02)
    Stream(03)
    Stream(04)
    Stream(05)
    Stream(06)
    PS C:\> $mBandwidth
    BANDWIDTH=396000
    BANDWIDTH=796000
    BANDWIDTH=996000
    BANDWIDTH=2096000
    BANDWIDTH=3096000
    BANDWIDTH=5096000
    PS C:\> $mResolution
    RESOLUTION=384x216
    RESOLUTION=512x288
    RESOLUTION=640x360
    RESOLUTION=960x540
    RESOLUTION=1280x720
    RESOLUTION=1280x720

    I want to combine them to show as follows:

    PS C:\> $manifest
    
    Stream          BANDWIDTH            RESOLUTION
    ----------      ---------            ----------
    Stream(01)      BANDWIDTH=396000     RESOLUTION=384x216
    Stream(02)      BANDWIDTH=796000     RESOLUTION=512x288
    Stream(03)      BANDWIDTH=996000     RESOLUTION=640x360
    Stream(04)      BANDWIDTH=2096000    RESOLUTION=960x540
    Stream(05)      BANDWIDTH=3096000    RESOLUTION=1280x720
    Stream(06)      BANDWIDTH=5096000    RESOLUTION=1280x720


    I have used 3 "foreach" on within the other but it results in 6x6x6 loops, repeating results.

    i'm leaning scrip and i have been googling for a way to do it but so far noting...

    that's the closer i got:

    Select-String -Path ".\$Version\$PName\index.m3u8" -pattern 'Stream\(\d+\)' | foreach {$_.matches.value} {
    $mObject = "" | Select "Stream", "Bandwidth", "Resolution"
    $mObject.Stream = $_.matches.value
    $outarray += $mObject
    $mObject = $null}
    Select-String -Path ".\$Version\$PName\index.m3u8" -pattern 'BANDWIDTH=\d+' | foreach {$_.matches.value} {
    $mObject = "" | Select "Stream", "Bandwidth", "Resolution"
    $mObject.Bandwidth = $_.matches.value
    $outarray += $mObject
    $mObject = $null}
    Select-String -Path ".\$Version\$PName\index.m3u8" -pattern 'RESOLUTION=\d+.\d+' | foreach {$_.matches.value} {
    $mObject = "" | Select "Stream", "Bandwidth", "Resolution"
    $mObject.Resolution = $_.matches.value
    $outarray += $mObject
    $mObject = $null
    }
    $OutArray
    
    Stream     Bandwidth         Resolution
    ------     ---------         ----------
    Stream(01)
    Stream(02)
    Stream(03)
    Stream(04)
    Stream(05)
    Stream(06)
               BANDWIDTH=396000
               BANDWIDTH=796000
               BANDWIDTH=996000
               BANDWIDTH=2096000
               BANDWIDTH=3096000
               BANDWIDTH=5096000
                                 RESOLUTION=384x216
                                 RESOLUTION=512x288
                                 RESOLUTION=640x360
                                 RESOLUTION=960x540
                                 RESOLUTION=1280x720
                                 RESOLUTION=1280x720

    Any tips are really appreciated.

    thanks!

    Wednesday, November 28, 2018 2:20 AM

Answers

  • This is how:

    for($i=0;$i -lt $mstream.Count;$i++){
        [pscustomobject]@{
            Stream = $mstream[$i]
            BandWidth = $mBandwidth[$i]
            Resolution = $mResolution[$i]
        }
    }
    


    \_(ツ)_/

    Wednesday, November 28, 2018 2:36 AM

All replies

  • This is how:

    for($i=0;$i -lt $mstream.Count;$i++){
        [pscustomobject]@{
            Stream = $mstream[$i]
            BandWidth = $mBandwidth[$i]
            Resolution = $mResolution[$i]
        }
    }
    


    \_(ツ)_/

    Wednesday, November 28, 2018 2:36 AM
  • $TotalOut=@()

    for($i=0;$i -lt $mstream.count;$i++){

    $out=""| Select Stream,BandWidth,Resolution

    $out.Stream=$mstream[$i]

    $out.BandWidth=$mBandwidth[$i]

    $out.Resolution=$mResolution[$i]

    $TotalOut+=$out

    }

    $TotalOut|Export-csv -path C:\output.csv -notypeInformation


    Wednesday, November 28, 2018 3:39 AM
  • Thanks guys!

    I see that both approaches are similar but Akash_Automation is easier to understand...

    For jrv's suggestion I just added a tiny (obvious) addition:

    $B = for($i=0;$i -lt $mstream.Count;$i++){
        [pscustomobject]@{
            Stream = $mstream[$i]
            BandWidth = $mBandwidth[$i]
            Resolution = $mResolution[$i]
        }
    }

    that way, $B holds the content for later usage.

    I now need time to understand why the creation of PScustomobject should be inside the loop, being created and executed each time, but this is another subject.

    After post this question, I continued searching for a solution using different words then I found the following option what attended me at that moment.

    0..($mStream.Count - 1) | ForEach-Object {$manifest += @("$($mStream[$_])`t$($mBandwidth[$_])`t$($mResolution[$_])")}

    It differs that the output is TAB formatted and not a PS custom object.

    Author: Curtis

    https://powershell.org/forums/topic/combine-individual-items-from-separate-arrays-into-a-third-array/


    • Edited by Ed.Wilson Friday, November 30, 2018 5:24 PM
    Friday, November 30, 2018 5:21 PM
  • Simple:

    0..($mStream.Count - 1) | 
        ForEach-Object{
            [pscustomobject]@{
                Stream = $mstream[$_]
                BandWidth = $mBandwidth[$_]
                Resolution = $mResolution[$_]
            }
        } |
        Export-Csv file.csv


    \_(ツ)_/


    • Edited by jrv Friday, November 30, 2018 5:32 PM
    Friday, November 30, 2018 5:31 PM