How do I include this field into Out-gridview

Welcome Forums General PowerShell Q&A How do I include this field into Out-gridview

This topic contains 2 replies, has 2 voices, and was last updated by

3 days, 3 hours ago.

  • Author
  • #151611

    Points: 475
    Rank: Contributor
    # --- $groups is 6 separate .TXT files
    # --- $titles is a .CSV file, each line containing a few words (book title)
    $titles = Import-csv .\Mysource.csv
    # --- check existence of each line in $titles in each of the 6 groups in $groups
    $dups = Foreach ($mt in $titles) {
                [string]$mtstring = $mt.TitleWoYear
                Foreach ($g in $groups) {
                     $Gfile = 'C:\TEMP\ + $g + '.txt'
                     $thisgroup = Get-content -path $Gfile
                     $thisgroup | Out-string -stream |
                     Select-string -pattern $mtstring -simplematch -list
    $dups | Out-gridview

    The above works OK.  I have grappled with how I can include the value of $g (a file name) into the output using Out-Gridview (if possible?)  I tried reversing the inner Foreach loop with the outer Foreach loop but discovered the -Begin / -Process / -End blocks are not allowed in Foreach ($a in $b) looping, only for Foreach-object (pipelining).  Would be grateful for some advice or insights/tips.  Many thanks.

  • #151629

    Points: 1,959
    Helping Hand
    Rank: Community Hero

    Using Out-GridView in a script will effect automation, especially in loops. But If you really want to do this, you can put it inside the inner foreach as well. Else you can use Foreach-Object for $groups.

    Foreach($mt in $titles){
    $groups | ForEach-Object ...
    • #151700

      Points: 475
      Rank: Contributor

      Yes, Mr KVPrasoon ... I'm glad you sensitized me to this aspect of the impact of Out-gridview during processing.  Indeed, it can become disruptive.  What I typically do is insert Out-gridview at "key points" when I am still developing the script, and then comment it out when "final".

      My sincerest thanks for your continuing advice and assistance, and generous sharing of technical knowledge.

You must be logged in to reply to this topic.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort