Noob Powershell String Parsing Question

  • I am very new to Powershell and am trying to solve what appears to be a very simple problem.

    I have a variable called $TestLocations

    The value of $TestLocations is:

    xxx

    ----------

    2

    23

    44

    65

    I need to extract the values of Lines 3,4,5 & 6 and assign their values to an array. E.g. if I had an array called #x it would look like this:

    #x = @((2),(23),(44),(65))

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • I figured it out...

    $myArray =@()

    foreach ($item in $TestLocations) { $myArray += $item.LineNumber }

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply