Hej,
mam skrypt, który sprawdza ilość wolnego miejsca na dyskach i generuje raport email w html i wysyła do mnie. Mam jednak rpbolem, bo dany html się nie formatuje i wygląda tak:
@{SystemName=K005; DeviceID=U:; VolumeName=Nowy; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.SystemName @{SystemName=K005; DeviceID=U:; VolumeName=Nowy; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.DeviceID @{SystemName=K005; DeviceID=U:; VolumeName=New; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.VolumeName @{SystemName=K005; DeviceID=U:; VolumeName=Nowy; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.'FreeSpace(GB)' @{SystemName=K005; DeviceID=U:; VolumeName=New; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.'Size(GB)' @{SystemName=K005; DeviceID=U:; VolumeName=Nowy; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.'PercentFree(%)' @{SystemName=K005; DeviceID=U:; VolumeName=Nowy; FreeSpace(GB)=87,4; Size(GB)=465,8; PercentFree(%)=}.'LOW SPACE'
XXX Offline
XXX Offline
Te dwa ostatnie wpisy Offline są generowane dobrze, chodzi tylko o tą tabelę z informacji o kompach, które są dostępne.
Tabela powinna wyglądać tak jak w załączniku.
Skrypt:
Function Get-ComInfo
{
param(
$computers
)
#Here LOW Space thresold is lessthan 10% of the total size of the Volume
$PercentFree = @{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($_.freespace /1GB)}}
Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computer $computers -ErrorAction SilentlyContinue|
Select SystemName,DeviceID,VolumeName,$PercentFree,@{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{name="PercentFree(%)";Expression={int}}
}
$html=
"
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>HTML TABLE</title>
<style type='text/css'>
.alert {{
background-color: #FB1717 }}
</style>
</head>
<body>
<table>
<colgroup><col/><col/><col/><col/><col/><col/><col/></colgroup>
"
Get-Content U:\Users\XXX\Desktop\servers.txt | ForEach-Object {
if(!(test-connection -computername $_ -quiet -count 1))
{
$html += "<tr><td>$_</td><td>Offline</td><td></td><td></td><td></td><td></td><td></td></tr>"
}
else
{
# $entries = Get-Content U:\Users\XXX\Desktop\servers.txt | % { Get-ComInfo -computers $_ } | ForEach-Object {
Get-ComInfo -computers $_ | ForEach-Object {
if ([float]::Parse($_.'FreeSpace(GB)') -le 5)
{
#$alertEntryTemplate -f $_.SystemName, $_.DeviceID, $_.VolumeName, $_.'FreeSpace(GB)', $_.'Size(GB)', $_.'PercentFree(%)', $_.'LOW SPACE'
$html += "<tr class='alert'><tr><td>$_.SystemName</td><td>$_.DeviceID</td><td>$_.VolumeName</td><td>$_.'FreeSpace(GB)'</td><td>$_.'Size(GB)'</td><td>$_.'PercentFree(%)'</td><td>$_.'LOW SPACE'</td></tr>"
}
else
{
#$entryTemplate -f $_.SystemName, $_.DeviceID, $_.VolumeName, $_.'FreeSpace(GB)', $_.'Size(GB)', $_.'PercentFree(%)', $_.'LOW SPACE'
$html += "<tr><td>$_.SystemName</td><td>$_.DeviceID</td><td>$_.VolumeName</td><td>$_.'FreeSpace(GB)'</td><td>$_.'Size(GB)'</td><td>$_.'PercentFree(%)'</td><td>$_.'LOW SPACE'</td></tr>"
}
}
}
}
$html +=
"
</table>
</body>
</html>
"
$SMTPServer = "smtp.XXX.XXX"
$EmailFrom = "XXX@XXX.XXX"
$EmailTo = "XXX@XXX.XXX"
$Subject = "$computers PROGRES ;))"
$body = $html
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.EnableSsl = $false
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("XXX", "XXX");
$msg.Body = $html
$msg = New-object Net.Mail.MailMessage($EmailFrom, $EmailTo, $Subject, $body)
$msg.IsBodyHTML = $true
$SMTPClient.Send($msg)