3
\$\begingroup\$

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"
######################################################################
######################################################################
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Aug 4, 2014 at 17:19
\$\endgroup\$
2
  • \$\begingroup\$ Could you please describe this code? \$\endgroup\$ Commented Aug 4, 2014 at 17:22
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Aug 4, 2014 at 17:23

1 Answer 1

1
\$\begingroup\$

Assuming you commented out the second file generation of these two:

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"
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"

You can combine the above lines using the -LiteralPath parameter to Get-ChildItem, like so:

GET-CONTENT (GET-CHILDITEM -LiteralPath 'E:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS3\*.out', 'C:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS56\*.out') | out-file -encoding "UTF8" "C:\Users\jsweeton\Documents\SITES\CBM\Storage Analysis\CBM-FS3\CBM-FS3.txt"

If that's not what you're looking for or you need more input, just let me know and I'll update my answer accordingly.

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
answered Jun 29, 2015 at 15:34
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.