Solved

Exchange 2007 Lab Scripts

Posted on 2013-01-27
4
222 Views
Last Modified: 2013-01-31
I need some scripts that would say any IIS or SMTP logs older than XYZ days to be moved to ABC folder and send me an email with the data copied
0
Comment
Question by:vicky19
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:S_K_S
S_K_S earned 150 total points
Comment Utility
0
 
LVL 5

Accepted Solution

by:
coraxal earned 150 total points
Comment Utility
I don't remember exactly the folder paths for IIS or SMTP logs...but this PowerShell script (version 2) should be easily modified to your environment. Also, I'm not sure whether you want to move or copy; I assumed copy but you can change Copy-Item to Move-Item if moving file is your goal

 
$Now = Get-Date 
$SourceFolderPaths = "C:\iislogs\*","C:\smtplogs\*" #change folder paths
$TargetFolderPath = "C:\newpath\" #change folder path
$LastWrite = $Now.AddDays(-45) #change days threshold
$LogFile = "C:\Temp\filecleanup.log" #change log file path and name

if(Test-Path -Path $LogFile -PathType Leaf)
{
	Write-Output "Removing log file $LogFile"
	Remove-Item $LogFile | Out-Null
} else {
	Write-Output "Creating log file $LogFile"
	New-Item -ItemType file $LogFile | Out-Null
}
	
Write-Output "========= Starting file cleanup ==========" >> $LogFile

# for multiple file extensions:  *.txt,*.gif,*.html
$Files = $FolderPaths | % {Get-Childitem $_ -Include *.log } | 
Where-Object {$_.LastWriteTime -le $LastWrite}

if($Files -ne $null){
	$Files | % {
        Write-Output "Copying file: $($_.FullName) to: $TargetFolderPath" >> $LogFile
        Copy-Item $_.FullName -Destination $TargetFolderPath | Out-Null
    }
} else {
	Write-Output "There no files to copy" >> $LogFile
}
Write-Output "========= Ending file cleanup ==========" >> $LogFile

Send-MailMessage -From "Admin <admin@noreply.com>" `
	-To "John Doe <john.doe@domain.com>" `
	-Subject "Log file cleanup task" `
	-Body "This is an email notification." `
	-Attachments $LogFile `
	-SmtpServer "YOURSERVER.domain.com"

Open in new window

0
 
LVL 4

Author Comment

by:vicky19
Comment Utility
Thanks S_K_S and Coraxal will check with your answers
0
 
LVL 4

Author Closing Comment

by:vicky19
Comment Utility
Thanks guys not getting time to check but if issues will raise another query and post here for your assistance out there
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
This video discusses moving either the default database or any database to a new volume.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now