Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Foreach loop through multiple CSV files fails after 3rd file

$
0
0

I have a folder with 7 CSV files and I'm attempting to loop through each and parse two cells

The cell values consist of computer and process name and I'll use the variables in some other copy functions

I can grab the values in the first two files and then it no longer gives the values from the other csv files in my folder path "C:\Depot"

The field1 and field2 items are what ciall from each CSV and they are named sheet1.csv thru sheet7 .csv

Here is the data in may CSV files

Sheet1.CSV -- data below

Workstation  Date          Process

Machine1      10/1/2013  Excel.exe

Sheet2.CSV -- data below

Workstation  Date          Process

VMachine1    10/2/2013  Adobe.exe

Code below ------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

# $ErrorActionPreference = "SilentlyContinue"

$GetFiles

 

 

=DIR-Path'c:\Depot\*.CSV'-Exclude 'Log*.*'

Foreach 

 

( $Filein$GetFiles  )

{

$data

 

=Import-Csv $file

# :outer

 

 

# $Cells = Import-Csv $GetFiles

 

 

$Counter 0

foreach 

 

( $iin$data  )

{

 

 

$Field1=$i.Workstation

 

 

$Field2=$i.Process

 

 

# Import-Csv $File

 

Write-Host 

 

 

$Counter ++

 

 

If ( $?-eq$false  )

{

 

 

break

}

 

 

elseif ( $Counter-eq  2 )

{

 

 

break

}

 

}

 

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thanks and any help is appreciated with this issue

$Field1, $Field2

Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images