Solved

PowerShell to dump a particular folders

Posted on 2014-09-15
5
82 Views
Last Modified: 2014-09-16
How to list all the folders and files with last modified date and send out an email using powershell ?

Tks
0
Comment
Question by:AXISHK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 40322643
Try this code, this will report the details in an HTML mail.. You can also attach the details in a csv file if required.
$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>"

$Body = Get-ChildItem D:\Folder -Recurse | 
   Select Name,FullName,LastWriteTime |
	 ConvertTo-HTML -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

Open in new window

0
 

Author Comment

by:AXISHK
ID: 40322720
Tks. How to modify the code to include CSV as a attachment ?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40323275
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

Open in new window

0
 

Author Comment

by:AXISHK
ID: 40324843
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 ?
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40324857
Those are parameters of Send-MailMessage command.. You can read help here..

http://ss64.com/ps/send-mailmessage.html

Let me know if you need further details on any particular parameter..

' means the command continues in next line..
http://www.computerperformance.co.uk/powershell/powershell_backtick.htm
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question