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
199 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
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…

738 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