Solved

Exchange 2007 Lab Scripts

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

813 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

17 Experts available now in Live!

Get 1:1 Help Now