Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exchange 2007 Lab Scripts

Posted on 2013-01-27
4
Medium Priority
?
271 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 7

Assisted Solution

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

Accepted Solution

by:
coraxal earned 600 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

721 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