change to only check one folder and record double


 i run code on multiple folders , works. if check single share 2 differnt files on share it doubles output file. it's processing found files twice. want supply folder (parm) , 2 csv files combine single output file.

 thanks.

function search-files{        param([string[]]$locations,[string[]]$searchfor, $appendto)      begin      {          if(-not (test-path $appendto)){new-item $appendto -itemtype file -force}      }        process      {          foreach($location in $locations)          {             $files = get-childitem -path $location -filter $searchfor -recurse               foreach($file in $files)             {                  get-content -path $files.fullname | out-file $appendto -append             }          }      }        end{}  }      search-files -locations "\\servera\public\t1\usa\saleshist\",\\serverb\public\t2\usa\saleshist\ -searchfor "dodetail-cm.txt","somstr.txt" -appendto "\\virt1\saleshist_data_load_files\saleshdr.load.csv"

your get-content line in files section using $files.fullname instead of $file.fullname, should instead:

get-content -path $file.fullname | out-file $appendto -append


i hope post has helped!



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file