none
Split method in Powershell RRS feed

  • Question

  • I have flat file containing records where fields in each record are separated by (comma/","). Am trying to use the split method to retrieve the each field in the record.  

    My code is as follows:

    $Final_Read_Records = Get-Content -Path "C:\CCb-Final-Reads.txt"
    foreach ($Final_Read_Rec in $Final_Read_Records)
      {
       $Device_ID = $Final_Read_Rec.split("{,}",1)
       $Read_Date = $Final_Read_Rec.split("{,}", 2)
          if ($First_Pass = 1)
       {echo "FirstPass" $First_Pass
       $Where_Clause_Full = $Where_Clause + $Right_Parenthesis + $Device_ID + $And_Clause + $Read_Date + $Left_Parenthesis + $OR_Clause
       $First_Pass = 0
          }

    So far I have not been successful obtaining each field.  I guess I don't understand how the split method works.  What I'm I doing wrong.  

    Thanks

    Tuesday, October 24, 2017 3:24 PM

Answers

  •  $Device_ID,  $Read_Date  = $Final_Read_Rec -split
      

    \_(ツ)_/

    • Marked as answer by Louisb Tuesday, October 24, 2017 7:41 PM
    Tuesday, October 24, 2017 5:08 PM

All replies

  •  $Device_ID,  $Read_Date  = $Final_Read_Rec -split
      

    \_(ツ)_/

    • Marked as answer by Louisb Tuesday, October 24, 2017 7:41 PM
    Tuesday, October 24, 2017 5:08 PM
  • I'm using a switch as part of the programming logic.  I set the value of the switch to 1 as such:

    First_Pass = 1

    Once have executed the some code I want to change the value to 0.  I'm doing this as follows:

    First_Pass = 0 

    The above does not work, I've tried several method and nothing works.  

    How do I change the content of a variable.  It seem so simply but is so hard.

    Thanks

     

    Tuesday, October 24, 2017 6:58 PM