Link to home
Start Free TrialLog in
Avatar of adiemeer
adiemeer

asked on

Sending e-mail using Powershell 3.0

Hello,

I am using powershell to detect which files are recently added to some predefined file locations. See next powershell code:

$time = (Get-Date).AddDays(-30)
$changes =  new-object System.Xml.XmlDocument
$changes.load("C:\test\locations.xml")
      $items = $changes.SelectNodes("//application") | select
      foreach ($item in $items)
        {
                  $location = $item.SelectSingleNode("./location") | % { $_.InnerText }
                  Get-ChildItem $location | `
            Where-Object {$_.LastWriteTime -gt $time}
        }

This files reads the locations defined in the c:\test\locations.xml file, and displays for each of these locations which files are added in the last 30 days.

Now, I want to e-mail this list. The next powershell command works fine when I want to send an e-mail:

Send-MailMessage -To "user@test.nl" -From "noreply@test.nl" -Subject "Test mail"  -Body "This is a test" -SmtpServer "SMTP server"

But now I want to e-mail the filelist. How can I manage to include the result of my first powershell script in the -Body of my second powershell script?

Regards,

Arne
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adiemeer
adiemeer

ASKER

Thanks! This works fine!