Solved

Exchange 2007 Lab Scripts

Posted on 2013-01-27
4
259 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
[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
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:S_K_S
S_K_S earned 150 total points
ID: 38823957
0
 
LVL 5

Accepted Solution

by:
coraxal earned 150 total points
ID: 38823976
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
ID: 38836213
Thanks S_K_S and Coraxal will check with your answers
0
 
LVL 4

Author Closing Comment

by:vicky19
ID: 38841256
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

751 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