Abuzar Anis
Abuzar Anis

Reputation: 45

format output to body of mail using powershell

I want to display the disk size of certain directory and file for a particular directory in a formatted output and send it as a body in the mail using powershell.

I used in the powershell code but not able to save the same in a variable:

     C:\Users\abc\Desktop\xyz\file.bat -Name powershell | Format-Wide

The file.bat is :

    cd C:\Program Files (x86)\Resource Kit
    diruse  /M /* C:\Users\abc\Desktop

and the output is :

Size (mb)  Files  Directory
     0.18     23  SUB-TOTAL: C:\USERS\abc\DESKTOP\xyz
    76.40      5  SUB-TOTAL: C:\USERS\abc\DESKTOP\testreport
    76.58     28  TOTAL

I want to print this output in the body of the mail using powershell. Could any one please look into it as how to save the formatted output in a variable in powershell so that i can get the output

Upvotes: 0

Views: 2091

Answers (1)

mjolinor
mjolinor

Reputation: 68341

You can get an approximate format of that in an email body by piping it through Out-String

$body = C:\Users\abc\Desktop\xyz\file.bat -Name powershell | Format-Wide | Out-String

Note that your column alignment will not be exactly as you see it in the console, because the email client will use proportional fonts, where the console uses a fixed width font.

Upvotes: 1

Related Questions