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\loc ations.xml ")
$items = $changes.SelectNodes("//ap plication" ) | 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
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\loc
$items = $changes.SelectNodes("//ap
foreach ($item in $items)
{
$location = $item.SelectSingleNode("./
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER