Question Show Disk Space via WMI

Plus d'informations
il y a 13 ans 2 mois #8607 par maycry
Réponse de maycry sur le sujet Re:Show Disk Space via WMI
Voici e Script: ( usine à gaz mais fonctionne une fois les params renseigné)

Je m'en suis servis également en rajoutant des requêtes LDAP pour aller récupérer par exemple les serveurs présent dans un groupe global.

[code:1]
<#
######################################################################################################################################
#=====================================
# Get-DiskSpace-Servers-WebHTML.ps1
# Bousquet Christian
# V2.0
# 2 File .js must have present
# ===> jsjquery.min.js
# ===> animatedcollapse.js
#======================================
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# This Script will make Report HTML with JavaScript Expand and collapse all servers
# Disk Space Type = 3
# All Label
# Disk ID
# Total Space
# Free Space and Percent
# Used Space and Percent
#
# STEP 0 ==> PATH JAVASCRIPT ( Put the path for JS)
# Step 1 ==> CMLDLETS ACTION ( enter your info for run script )
# STEP 2 ==> Optionnal Information ( this information to modify the script to impact directly)
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#######################################################################################################################################
#>

#============================================================================
# Step 0 ==> PATH JAVASCRIPT
#============================================================================
$JavaScriptJquery = \"C:\jquery.min.js\"
$JAvaScriptAnimatedCollapse = \"C:\animatedcollapse.js\"
#============================================================================
# ENS Step 0 ==> PATH JAVASCRIPT
#============================================================================

####################################################################################

#============================================================================
# Step 1 ==> CMLDLETS ACTION
#============================================================================
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# First lets create a text file, where we will later save the freedisk space info
$date = ( get-date ).ToString('dd-MM-yyyy')

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Name of your compagny
$ClientEnterprise = \"Chrisme Corp Microsoft\"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Where Save your Report ?
$FileNameReportDisk = \"c:\Disk_Space_Report-$date.html\"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Add Server From File Source or enum
$ListServer = \"dcdsmiami102\",\"dcmiami101\",\"exmiami105\",\"dcds\",\"server fail\",\"dcdsmiami.chrisme.ms\",\"exmiami.chrisme.ms\",\"exchange.chrisme.ms\",\"domaincontroller.chrisme.ms\"
#$ListServer = Get-Content \"C:\PowerShell-Server\Scripts\ListServer.log\"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Edit the title of Web Page
$TitleHtml = \"CheckDisk MIAMI- $date\"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$DescriptionGeneral = \"ZONE MIAMI \"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
MAIL REPORT
$From = \"Disk-Report@chrisme.ms\"
$To = \"MSUser1@chrisme.ms\"
$Subject= \"Disk Space Report - $date\"
$Smtp = \"exmiami105\"
$FileAttach = $freeSpaceFileName
#
MAIL REPORT

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
ALERT MAIL REPORT (Critical)
$ToCritical = \"MSUser1@chrisme.ms\"
$subjectCritical = \"Alerte Low\"
#
MAIL REPORT
#============================================================================
# END Step 1 ==> CMLDLETS ACTION
#============================================================================



#============================================================================
# STEP 2 ==> Optionnal Information
#============================================================================
#Optionnal Advertisment
$warning = 35
$critical = 20

#Date info HTML
$date = ( get-date ).ToString('dd/MM/yyyy')
$dateorigin = Get-Date

# Count Server For HTML
$CountServer = $ListServer.count
#============================================================================
# End STEP 2 ==> Optionnal Information
#============================================================================

####################################################################################
####################################################################################

#================================
# FUNCTIONS CATEGORIE
#================================


# *************************
# Function Uptime
# *************************
function Get-Uptime
{
param([string]$server)
Begin {
function Uptime {
param([string]$srv)
$os = Get-WmiObject Win32_OperatingSystem -ComputerName $srv
$uptime = $os.LastBootUpTime
return $uptime
}
function ConvertDate {
param([string]$date)
$year = $date.substring(0,4)
$Month = $date.Substring(4,2)
$Day = $date.Substring(6,2)
$hour = $date.Substring(8,2)
$min = $date.Substring(10,2)
$sec = $date.Substring(12,2)
$RebootTime = new-Object System.DateTime($year,$month,$day,$hour,$min,$sec)
$now = [System.DateTime]::Now
$uptime = $now.Subtract($RebootTime)

$report = \"Allumé depuis ==>: $($uptime.days)jours,$($uptime.Hours)Heures,$($uptime.Minutes)Minutes,$($uptime.seconds)Secondes\"
$report
}

$result = uptime $server
#Write-Host \"Uptime for Server [\" -NoNewline
#Write-Host $server -NoNewline -foregroundcolor Cyan
#Write-Host \"]\"
ConvertDate $result
#Write-Host
}
#Write-Host
}
# *************************
# END Function Uptime
# *************************

# ******************************
# Function DEscription Server
# ******************************
function Get-DescriptionServer
{
param([string]$server)
(gwmi -class win32_operatingsystem -ComputerName $Server).description
}
# ******************************
# END Function DEscription Server
# ******************************


#================================
# END FUNCTIONS CATEGORIE
#================================



#================================
# CATEGORIES HTML
#================================

New-Item -ItemType file $FileNameReportDisk -Force

# Function to write the HTML Header to the file
Function writeHtmlHeader

{

param($FileName)



Add-Content $FileName \"<html>\"
Add-Content $FileName \"<head>\"
Add-Content $FileName \"<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\"

#*************************************************************
# Title HTML
#*************************************************************
Add-Content $FileName \"<title>$TitleHtml</title>\"
#*************************************************************
# End Title HTML
#*************************************************************


#=============================================================
# Start Write Put JAVASCRIPT
#=============================================================
Add-Content $FileName \"<script type='text/javascript'>\"
$readjquery = get-content $JavaScriptJquery
Add-Content $FileName $readjquery

Add-Content $FileName \"</script>\"

Add-Content $FileName \"<script type='text/javascript'>\"
$readcollapse = Get-Content $JAvaScriptAnimatedCollapse
Add-Content $FileName $readcollapse
Add-Content $FileName \"</script>\"
#=============================================================
# End Write Put JAVASCRIPT
#=============================================================

#=============================================================
# Start JAvascript Animated
# This functionn Add each <div> for all table need Expand or Collapse
#=============================================================
Add-Content $FileName \"<script type='text/javascript'>\"

$ToggleID = 0
foreach ($ServerName in $ListServer)
{
Add-Content $FileName \"animatedcollapse.addDiv('toggle$ToggleID', 'fade=1')\"
$ToggleID++
}
#=============================================================
# End Java Script Animated
#=============================================================


Add-Content $FileName \"animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted\"
Add-Content $FileName \"//$: Access to jQuery\"
Add-Content $FileName \"//divobj: DOM reference to DIV being expanded/ collapsed. Use divobj.id to get its ID\"
Add-Content $FileName \"//state: block or none, depending on state\"
Add-Content $FileName \"}\"
Add-Content $FileName \"animatedcollapse.init()\"
Add-Content $FileName \"</script>\"
add-content $FileName \"<STYLE TYPE='text/css'>\"
add-content $FileName \"<!--\"
add-content $FileName \"table {\"
add-content $FileName \"border: medium solid #CCCCCC;\"
add-content $FileName \"border-collapse: collapse;\"
add-content $FileName \"}\"
add-content $FileName \"th {\"
add-content $FileName \"padding: 5px;\"
add-content $FileName \"background-color: #71D2FF;\"
add-content $FileName \"}\"
add-content $FileName \"td \"
add-content $FileName \"{\"
add-content $FileName \"font-family: sans-serif;\"
add-content $FileName \"border: thin solid #6495ed;\"
add-content $FileName \"padding: 5px;\"
add-content $FileName \"text-align: center;\"
add-content $FileName \"}\"
add-content $FileName \".heading0_expanded\"
add-content $FileName \"{\"
add-content $FileName \"BORDER-RIGHT: #bbbbbb 1px solid; PADDING-RIGHT: 5em; BORDER-TOP: #bbbbbb 1px solid; DISPLAY: block; PADDING-LEFT: 20px; FONT-WEIGHT: bold; FONT-SIZE: 16pt; MARGIN-BOTTOM: -1px; MARGIN-LEFT: 0px; BORDER-LEFT: #bbbbbb 1px solid; CURSOR: hand; COLOR: White; MARGIN-RIGHT: 0px; FONT-FAMILY: Tahoma; POSITION: relative; HEIGHT: 1.25em; BACKGROUND-COLOR: #C22523\"
add-content $FileName \"}\"
add-content $FileName \"A.showhide\"
add-content $FileName \"{\"
add-content $FileName \"font-family:arial;\"
add-content $FileName \"font-size:11pt;\"
add-content $FileName \"font-style:bold;\"
add-content $FileName \"border: black solid 1px;\"
add-content $FileName \"background:lightgrey;\"
add-content $FileName \"color:black; text-decoration:none;\"
add-content $FileName \"}\"
add-content $FileName \".buttonall\"
add-content $FileName \"{\"
add-content $FileName \"border: 2px solid white;\"
add-content $FileName \"width: 125px;\"
add-content $FileName \"font-size:10pt;\"
add-content $FileName \"font-familly:Tahoma;\"
add-content $FileName \"font-weight:bold;\"
add-content $FileName \"cursor:pointer;\"
add-content $FileName \"}\"
add-content $FileName \".button\"
add-content $FileName \"{\"
add-content $FileName \"border: 1px solid white;\"
add-content $FileName \"background:transparent;\"
add-content $FileName \"font-weight:bold;\"
add-content $FileName \"font-family: Tahoma;\"
add-content $FileName \"font-size:14pt;\"
add-content $FileName \"color:blue;\"
add-content $FileName \"text-decoration:underline;\"
add-content $FileName \"cursor:pointer;\"
add-content $FileName \"}\"
add-content $FileName \"-->\"
add-content $FileName \"</style>\"
Add-Content $FileName \"</head>\"
Add-Content $FileName \"<body>\"
Add-Content $FileName \"<p><b><font face='Arial' size='5'>\"
Add-Content $FileName \"$TitleHtml<hr size='8' color='#CC0000'></font></b>\"
Add-Content $FileName \"<font face='Arial' size='3'><b><i>$ClientEnterprise $CountServer Servers</i></b></font><br>\"
Add-Content $FileName \"<font face='Arial' size='2'>Report generated on $dateorigin\"
Add-Content $FileName \"</font></p>\"
Add-Content $FileName \"<DIV class=heading0_expanded>\"

#=============================================================
# This Each for Zone and Server / Javascript each DIV SHOW ALL / HIDE ALL
#=============================================================
Add-Content $FileName \"<SPAN>$DescriptionGeneral &nbsp &nbsp &nbsp &nbsp<th width='20%'><input onClick=\"\"javascript:animatedcollapse.show([\"
$ToggleID = 0
foreach ($ServerName in $ListServer)
{
Add-Content $FileName \"'toggle$ToggleID',\"
$ToggleID++
}
Add-Content $FileName \"])\"\" class='buttonall' type='button' value='Expand ALL'/> <input onClick=\"\"javascript:animatedcollapse.hide([\"
$ToggleID = 0
foreach ($ServerName in $ListServer)
{
Add-Content $FileName \"'toggle$ToggleID',\"
$ToggleID++
}

Add-Content $FileName \"])\"\" class='buttonall' type='button' value='Collapse ALL'/></th></SPAN>\"
Add-Content $FileName \"</DIV>\"
#=============================================================
# End Java Script Expand & Collapse SHOW ALL / HIDE ALL
#=============================================================

##########################################################################################

}
#=============================================================
# Function to write the HTML TABLE INFO Header to the file
Function writeTableHeader

{

param($FileName)
Add-Content $FileName \"<tr bgcolor='lightgrey'>\"
Add-Content $FileName \"<td width='5%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Drive</td>\"
Add-Content $FileName \"<td width='10%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Drive Label</td>\"
Add-Content $FileName \"<td width='15%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Total Capacity(GB)</td>\"
Add-Content $FileName \"<td width='15%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Used Capacity(GB)</td>\"
Add-Content $FileName \"<td width='15%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Free Space(GB)</td>\"
Add-Content $FileName \"<td width='10%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Used Space %</td>\"
Add-Content $FileName \"<td width='10%' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Free Space %</td>\"
Add-Content $FileName \"</tr>\"
}
#=============================================================
# Function to write the HTML footer to the file
Function writeHtmlFooter

{

param($FileName)


Add-Content $FileName \"</body>\"
Add-Content $FileName \"</html>\"
}
#=============================================================
# # Function to write the HTML DISK INFO WMI to the file
Function writeDiskInfo
{
param($FileName,$devId,$volName,$frSpace,$totSpace)
$totSpace=[math]::Round(($totSpace/1073741824),3)
$frSpace=[Math]::Round(($frSpace/1073741824),3)
$usedSpace = $totSpace - $frspace
$usedSpace=[Math]::Round($usedSpace,3)
$UsedPercent = ($usedSpace/$totSpace)*100
$UsedPercent = [Math]::Round($UsedPercent,3)
$freePercent = ($frspace/$totSpace)*100
$freePercent = [Math]::Round($freePercent,3)

if ($freePercent -le $critical)
{
Add-Content $FileName \"<tr>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$devid</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$volName</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$totSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$usedSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$frSpace GB</td>\"
Add-Content $FileName \"<td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>$usedPercent%</td>\"
Add-Content $FileName \"<td bgcolor='#FF0000' align=center><span style='font-size: 10pt'><u>$freePercent%</u></td>\"
Add-Content $FileName \"</tr>\"

#========================================================================================
Write-Host -BackgroundColor blue -ForegroundColor white \"Status Critical ==> $ServerName\"
$ReadFileNameReport = (Get-Content $FileNameReportDisk)
$ReadLineToReplace = \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th>\"

if
(
$ReadFileNameReport |Where-Object {$_ -eq $ReadLineToReplace}
)
{
echo \" reanme the number line $ReadCount To Critial\"
$ReadCount = ($ReadFileNameReport|Where-Object {$_ -eq $ReadLineToReplace}).ReadCount
$Replace = $ReadFileNameReport[$ReadCount-1]=\"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>Critical!</td>\"
$ReadFileNameReport | Set-Content $FileNameReportDisk
}

$ReadLineToReplace = \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"
if
(
$ReadFileNameReport |Where-Object {$_ -eq \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"}
)
{
echo \" reanme the number line $ReadCount To Critial + Warning \"
$ReadCount = ($ReadFileNameReport|Where-Object {$_ -eq $ReadLineToReplace}).ReadCount
$Replace = $ReadFileNameReport[$ReadCount-1]=\"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>Critical!</td><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"
$ReadFileNameReport | Set-Content $FileNameReportDisk
}

#========================================================================================

#=============================================================
Write-Host \" *** -->Send mail Alert Critical to $toCritical\"
Send-MailMessage -From $from -To $ToCritical -Subject \"$subjectCritical $ServerName $devId $freepercent %- $date\" -SmtpServer $Smtp `
-Body \"the server Name $Server have next infos
$Drive Label->$devid -Total Capacity->$totspace GB >Used Capacity->$UsedSpace GB -Free Space->$FrSpace GB -Used Space->$usedpercent %- -Free Space percent->$freepercent %\"
#=============================================================
}
elseif ($freePercent -le $warning)
{
Add-Content $FileName \"<tr>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$devid</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$volName</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$totSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$usedSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$frSpace GB</td>\"
Add-Content $FileName \"<td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>$UsedPercent%</td>\"
Add-Content $FileName \"<td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>$freePercent%</td>\"
Add-Content $FileName \"</tr>\"


#========================================================================================
Write-Host -BackgroundColor Blue -ForegroundColor white \"Status Warning ==> $ServerName\"
$ReadFileNameReport = (Get-Content $FileNameReportDisk)
$ReadLineToReplace = \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th>\"

if
(
$ReadFileNameReport |Where-Object {$_ -eq $ReadLineToReplace}
)
{
Start-Sleep 1
write-host \"Rename Table Server Name in Critical State Disk Space\"
$ReadCount = ($ReadFileNameReport|Where-Object {$_ -eq $ReadLineToReplace}).ReadCount
$Replace = $ReadFileNameReport[$ReadCount-1]=\"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"
$ReadFileNameReport | Set-Content $FileNameReportDisk
}
else
{
echo \"Rename Critial+Warning\"
if ($ReadFileNameReport | Where-Object {$_ -eq \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>Critical!</td>\"}
)
{
$ReadCount = ($ReadFileNameReport | Where-Object {$_ -eq \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>Critical!</td>\"}).ReadCount
echo \"$ReadCount for Line Critical + Warning Status ==> Already Critical\"
$Replace =$ReadFileNameReport[$ReadCount-1]=\"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>Critical!</td><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"
$ReadFileNameReport | Set-Content $FileNameReportDisk
}
elseif ($ReadFileNameReport | Where-Object {$_ -eq \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"}
)
{
$ReadCount = ($ReadFileNameReport | Where-Object {$_ -eq \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"}).ReadCount
echo \"$ReadCount for Line Critical +Warning Status ==> Already Warning\"
$Replace =$ReadFileNameReport[$ReadCount-1]=\"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th><td bgcolor='#FF0000' align=center><span style='font-size: 10pt'>Critical!</td><td bgcolor='#FBB917' align=center><span style='font-size: 10pt'>Warning!</td>\"
$ReadFileNameReport | Set-Content $FileNameReportDisk
}
}
#========================================================================================
}
else
{
Add-Content $FileName \"<tr>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$devid</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$volName</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$totSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$usedSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$frSpace GB</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$UsedPercent%</td>\"
Add-Content $FileName \"<td><span style='font-size: 10pt'>$freePercent%</td>\"
Add-Content $FileName \"</tr>\"
}
Start-Sleep 2
}
#================================
# END CATEGORIES HTML
#================================


#=======================================
# WRITING HTML
#=======================================
#STEP 1
writeHtmlHeader $FileNameReportDisk

# STEP 2 GENERATE SERVER
$ToggleID = 0
foreach ($ServerName in $ListServer)
{
#
# Function Check Service WMI PINGSTATUS ==> Build HTML
#
##################
# Display intput
write-host -BackgroundColor Blue \"Server to Ping: $ServerName\"
$PingCheck = (Test-Connection -Quiet -ComputerName $ServerName)
# Display Results
if ($PingCheck)
{
# Now Ping the system
$Ping = get-wmiobject -Query \"select * from win32_Pingstatus where Address='$ServerName'\"
$IPV4 = ($Ping.IPV4Address).IPAddressToString
$PingTime = $Ping.responsetime
write-host -BackgroundColor Green -ForegroundColor black \"Server responded in: $Pingtime ms\"
\"Server have IP:$IPV4\"
#=============================================================
# Take Information For TAble
$UptimeServer = Get-Uptime $ServerName
$DescriptionServer = Get-DescriptionServer $ServerName

#=============================================================
# STEP 2.FORM TABLE
#
> Information ServerName
Add-Content $FileNameReportDisk \"<table width='100%'>\"
Add-Content $FileNameReportDisk \"<tr>\"
Add-Content $FileNameReportDisk \"<thead >\"
Add-Content $FileNameReportDisk \"<tr>\"
Add-Content $FileNameReportDisk \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th>\"
Add-Content $FileNameReportDisk \"</tr>\"
Add-Content $FileNameReportDisk \"</thead>\"
Add-Content $FileNameReportDisk \"</tr>\"
Add-Content $FileNameReportDisk \"</table>\"
Add-Content $FileNameReportDisk \"<div id='toggle$ToggleID'>\"
#
> Information Uptime & Description
Add-Content $FileNameReportDisk \"<table width='100%'>\"
Add-Content $FileNameReportDisk \"<tr bgcolor='#BCCA95'>\"
Add-Content $FileNameReportDisk \"<td colSpan='4' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Uptime Server </td>\"
Add-Content $FileNameReportDisk \"<td colSpan='3' style='font-weight:bold' align='center'><font face='Georgia'><span style='font-size: 12pt'>Description </td>\"
Add-Content $FileNameReportDisk \"</tr>\"
Add-Content $FileNameReportDisk \"<tr>\"
Add-Content $FileNameReportDisk \"<td colSpan='4' style='font-weight:bold' bgcolor='#FFF69A'><span style='font-size: 10pt'><u>$UptimeServer</u><br>Address IP:$IPV4</br>Time Ping:$PingTime ms</td>\"
Add-Content $FileNameReportDisk \"<td colSpan='3' bgcolor='#FFF69A' ><span style='font-size: 10pt'>$DescriptionServer</td>\"
Add-Content $FileNameReportDisk \"</tr>\"
}
else
{
\"Server did not respond ==> $ServerName\"
#================MAIL ALERT HOST TIME OUT =============================================
$PingResult = ping $ServerName
$DatePingTimeOut = (Get-Date)
Write-Host -BackgroundColor Red -ForegroundColor White \" *** -->Send mail Host Time out to $toCritical\"
Send-MailMessage -From $from -To $ToCritical -Subject \"Hostdown or TimeOut $ServerName-$DatePingTimeOut\" -SmtpServer $Smtp `
-Body \"Detail ==> $PingResult\"
#=============================================================
#=============================================================
# STEP 2.FORM TABLE
#
> Information ServerName
Add-Content $FileNameReportDisk \"<table width='100%'>\"
Add-Content $FileNameReportDisk \"<tr>\"
Add-Content $FileNameReportDisk \"<thead >\"
Add-Content $FileNameReportDisk \"<tr>\"
Add-Content $FileNameReportDisk \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th>\"
Add-Content $FileNameReportDisk \"</tr>\"
Add-Content $FileNameReportDisk \"</thead>\"
Add-Content $FileNameReportDisk \"</tr>\"
}
#
# End Function Check Service WMI PINGSTATUS ==> Build HTML
#
#
# Condition HOST LIVE Check Service WMI PINGSTATUS ==> Build HTML
#
if ($PingCheck)
{
#=============================================================
# STEP 3 TABLE INSET DISK INFO
writeTableHeader $FileNameReportDisk
$GetHDD = Get-WmiObject win32_logicaldisk -ComputerName $ServerName | Where-Object {$_.drivetype -eq 3}
foreach ($item in $GetHDD)
{
Write-Host $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
writeDiskInfo $FileNameReportDisk $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
}

}
else
{
Write-Host -BackgroundColor Red -ForegroundColor black \"Time out Not Construct HTML ==> $ServerName\"
$ReadFileNameReport = (Get-Content $FileNameReportDisk)
$ReadLineToReplace = \"<th width='100%'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>$ServerName</u></strong></font></a></th>\"

if
(
$ReadFileNameReport |Where-Object {$_ -eq $ReadLineToReplace}
)
{

write-host \"Rename Table Server Name in Critical State\"
$ReadCount = ($ReadFileNameReport|Where-Object {$_ -eq $ReadLineToReplace}).ReadCount
$Replace = $ReadFileNameReport[$ReadCount-1]=\"<td width='100%' bgcolor='#FF0000'><font face='tahoma' color='black'><span style='font-size: 14pt'/><a class='button' href=\"\"javascript:animatedcollapse.toggle('toggle$ToggleID')\"\"><strong><u>Host Time Out $ServerName</u></strong></font></td>\"
$ReadFileNameReport | Set-Content $FileNameReportDisk

Start-Sleep 2
}
Add-Content $FileNameReportDisk \"</table>\"
Add-Content $FileNameReportDisk \"<div id='toggle$ToggleID'>\"
Add-Content $FileNameReportDisk \"<table width='100%'>\"
Add-Content $FileNameReportDisk \"<td>$PingResult</td>\"
Add-Content $FileNameReportDisk \"</table>\"
}
#
# End Condition HOST LIVE Check Service WMI PINGSTATUS ==> Build HTML
#
Add-Content $FileNameReportDisk \"</table>\"
Add-Content $FileNameReportDisk \"<table><br/></table></div>\"
$ToggleID++
}
#=============================================================
# STEP 4 FOOTER
writeHtmlFooter $FileNameReportDisk
#=======================================
# END WRITE HTML
#=======================================
Function sendEmail
{
param($from,$to,$subject,$smtphost,$htmlFileName)
$body = Get-Content $FileNameReportDisk
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
$msg.isBodyhtml = $true
$smtp.send($msg)
}
sendEmail $From $To $subject $Smtp $FileAttach
#Remove-Item -Path $FileNameReportDisk -Confirm:$false -Force
[/code:1]<br><br>Message édité par: chris, à: 7/02/11 20:27

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.068 secondes
Propulsé par Kunena