Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Is there a simple way to combine the functions of this Powershell script? It would be nice to have it file to one output file instead of several output files.

    GET-DATE
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1000 -entrytype Information -message "START CBM_PARSE.ps1" -category 1
######################################################################
######################################################################
$SA_Location = "E:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS3"
SET-LOCATION $SA_Location
$filenames = @(GET-CHILDITEM $SA_Location -recurse -include *.csv)
$regex = '^([^-]+-[^-]+)-([A-Z])-(\d{4})(\d\d)(\d\d).+'

# $PIPE = ","
$PIPE = "$([char]0x2C)"

# $SLASH = "\"
$SLASH = "$([char]0x5C)"

# $DSLASH = "\"
$DSLASH = "$([char]0x5C)$([char]0x5C)"

foreach ($file in $filenames) {$outfile = "$file" + ".out"
$ReplaceString = ($file | Split-Path -leaf) -replace $regex,'$1|$3-$4-$5|$2:'
((GET-CONTENT $file| Out-String).Substring(7))  | FOREACH-OBJECT -Verbose {
       $_ -replace "\\","\\" `
        -replace $PIPE,"|" `
        -replace "E:",$ReplaceString `
    } | SET-CONTENT  $outfile
}
GET-DATE
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1002 -entrytype Information -message "END Parsing" -category 1
ECHO "END PARSE"
######################################################################
######################################################################

GET-DATE
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1000 -entrytype Information -message "START CBM-FS3" -category 1
GET-CONTENT (GET-CHILDITEM "E:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS3\*.out") | out-file -encoding "UTF8" "C:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS3\CBM-FS3.txt"
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1002 -entrytype Information -message "END CBM-FS3" -category 1
ECHO "END CBM-FS3"
<#
GET-DATE
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1000 -entrytype Information -message "START CBM-FS56" -category 1
GET-CONTENT (GET-CHILDITEM "C:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS56\*.out") | out-file -encoding "UTF8" "C:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS04\CBM-FS04.txt"
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1002 -entrytype Information -message "END CBM-FS56" -category 1
ECHO "END CBM-FS56"
#>
GET-DATE
WRITE-EVENTLOG -logname Application -Source BLERG -EventID 1002 -entrytype Information -message "END CBM_PARSE.ps1" -category 1
ECHO "END END"
######################################################################
######################################################################
share|improve this question
    
Could you please describe this code? –  Jamal Aug 4 '14 at 17:22
    
This script takes a CSV file, pulls information from the file name (machine name, date) and add it to columns in the csv. It then take all the output files, and rolls them up into one big txt file. From there, I import it into MySQL. –  Jerry Sweeton Aug 4 '14 at 17:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.