Solved

Exchange 2007 Lab Scripts

Posted on 2013-01-27
4
267 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

635 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