AXISHK
asked on
PowerShell to dump a particular folders
How to list all the folders and files with last modified date and send out an email using powershell ?
Tks
Tks
ASKER
Tks. How to modify the code to include CSV as a attachment ?
Do you need both HTML & CSV reports? if yes try following code..
$a = "<style>"
$a = $a + "BODY{background-color:White;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"
$Csv = "$($Env:TEMP)\Report.csv"
#collect data
$folder = Get-ChildItem D:\Folder -Recurse | Select Name,FullName,LastWriteTime
#Export to csv
$folder | Select Name,FullName,LastWriteTime | Export-Csv $Csv -nti
#Prepare HTML body
$Body = $folder | ConvertTo-HTML -Property Name,FullName,LastWriteTime -head $a -body "<H3>Folder Information</H3>"
$Date = Get-date -format "dd/MM/yy HH:mm:ss"
Send-MailMessage `
-Body ($Body | Out-String) `
-Subject "Folder Information - $Date" `
-From subsun@domain.com `
-To subsun@domain.com `
-SmtpServer smtp.domain.com `
-Attachments $Csv
ASKER
Send-MailMessage `
-Body ($Body | Out-String) `
-Subject "Folder Information - $Date" `
-From subsun@domain.com `
-To subsun@domain.com `
-SmtpServer smtp.domain.com `
-Attachments $Csv
What's the meaning for ' at the end of each statement ?
-Body ($Body | Out-String) `
-Subject "Folder Information - $Date" `
-From subsun@domain.com `
-To subsun@domain.com `
-SmtpServer smtp.domain.com `
-Attachments $Csv
What's the meaning for ' at the end of each statement ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window