?
Solved

i need script to email me the defragmentation analysis report for all servers (for all volume ) from input file,

Posted on 2014-09-18
5
Medium Priority
?
203 Views
Last Modified: 2015-02-04
I need a script to email defractmentation analysis report for all servers and there voulumes, script will take input from input file.
0
Comment
Question by:biplabmukh
[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
5 Comments
 
LVL 11

Accepted Solution

by:
Joe Klimis earned 2000 total points
ID: 40360991
Hi

I think this will do what you wanted


save the following code into a script , It can be used in the following ways ( localhost is the default  server )

.\script  server1,server2,server3

or

get-content Servers.txt | ,\ script

or

.\script   for the local machine.


You will need to update the email settings to match  you environment.

#fragmentation report
param($servers = @("localhost"))
$report=@()
foreach ($server in $servers)
{
#
#  find the disks
#
$disks = Get-WmiObject -class Win32_LogicalDisk -ComputerName $server -Filter "DriveType=3"
	#
	#  check fragmentation of each disk
	#
	foreach ( $disk in $disks) 
	{
	$drive = Get-WmiObject -Class Win32_Volume      -ComputerName $server -Filter "DriveLetter = '$($disk.deviceId)'"
	$report += ($drive.DefragAnalysis()).DefragAnalysis | select pscomputername,@{n="Drive";e={$drive.name}},AverageFragmentsPerFile,AverageFileSize,FreeSpacePercent,TotalFragmentedFiles,ExcessFolderFragments,FragmentedFolders
	}
}
#
### send email
#
 $smtp = "Exchange-Server" 
 $to = "Test User <test.user@gmail.com>" 
 $from = "Fragmentation Report <test.user@Yourdomain.com>" 
 $subject = "Server Fragmentation Report"  
 
$content =   $report |   ConvertTo-Html -Fragment -PreContent "<h2>Fragmentation Report $(Get-date):</h2>" | Out-String
 
$head = @'
<style>
body { background-color:#dddddd;
       font-family:Tahoma;
       font-size:12pt; }
td, th { border:1px solid black; 
         border-collapse:collapse; }
th { color:white;
     background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
</style>
'@
 
$Body = ConvertTo-HTML -head $head  -Body $content | Out-String

 
#### Now send the email using \> Send-MailMessage  
 
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml

Open in new window

0
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 40413053
how did you get on ?
0
 

Author Comment

by:biplabmukh
ID: 40426162
Thanks J, will check and let you know if it works or any issue.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

777 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