Email all output from Powershell script -


i have powershell script loops through number of files , writes file information console. gets output screen need send via email.

the email part easy, can't figure out how capture gets sent screen , send in body. here relevant code. first iteration gets stored in $emailbody variable.

edited example:

$backuplocations = #list of paths#  $emailbody="" $currentfile = "nothing" foreach ($loc in $backuplocations) {     $files = get-childitem "$loc\\*" -recurse -include *.bak         foreach ($file in $files) {         if (test-path $file) {             $prop = get-itemproperty -path "$file"             write-output $prop | tee-object -variable $currentfile             $emailbody += $currentfile         }     }      }   # code send $emailbody in email.  working fine.# 

what see on screen pages worth of file information such this:

    directory: \\directory\directory\directory\myfolder  mode                lastwritetime     length name                                                                                                                           ----                -------------     ------ ----                                                                                                                           -a---         5/10/2011  10:00 pm    1986048 file.bak  

admittedly have not rtfm , have hacked way through powershell point, please forgive me if answer obvious one.

shouldn't trying this:

$emailbody="" foreach ($file in $files) {     if ($file) {         $prop = get-itemproperty -path "$file"         write-output $prop | tee-object -variable currentfile         $emailbody += $currentfile     }         }  

there better ways doing though. if can give details on $files , whether want output console etc. can @ better script.

after update:

wouldn't below work you:

$files = gci "$loc\\*" -recurse -include *.bak write-host $files $emailbody = $files | ft 

i don't think else needed! test-path - why? doing gci, of course exists!


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -