L
Lazaroe
Why task scheduler doesn't execute my ps1. file, it contains next information, please find attached screenshot with information that I got it.
Your support is highly appreciated. Thanks!
[
$ServerListFile = "C:\Ethicon.txt"
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
$Result = @()
ForEach($computername in $ServerList)
{
$AVGProc = Get-WmiObject -computername $computername win32_processor |
Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" |
Select-object @{Name = "C PercentFree"; Expression = {“{0:N2}” -f (($_.FreeSpace / $_.Capacity)*100) } }
$result += [PSCustomObject] @{
ServerName = "$computername"
CPULoad = "$($AVGProc.Average)%"
MemLoad = "$($OS.MemoryUsage)%"
CDrive = "$($vol.'C PercentFree')%"
}
1..2 | % {
$a+=[Array] $result
}
$a | out-file ".\test.txt"
##out-file -FilePath 'C:\health\test.txt'
$Outputreport = "<HTML><TITLE> Server Health Report </TITLE>
<BODY background-coloreachpuff>
<font color =""#99000"" face=""Microsoft Tai le"">
<H2> Server Health Report </H2></font>
<Table border=1 cellpadding=0 cellspacing=0>
<TR bgcolor=gray align=center>
<TD><B>Server Name</B></TD>
<TD><B>Avrg.CPU Utilization</B></TD>
<TD><B>Memory Utilization</B></TD>
<TD><B>C Drive Utilizatoin</B></TD></TR>"
Foreach($Entry in $Result)
{
if((($Entry.CpuLoad) -or ($Entry.memload)) -ge "80")
{
$Outputreport += "<TR bgcolor=red>"
}
else
{
$Outputreport += "<TR>"
}
$Outputreport += "<TD>$($Entry.Servername)</TD><TD align=center>$($Entry.CPULoad)</TD><TD align=center>$($Entry.MemLoad)</TD><TD align=center>$($Entry.Cdrive)</TD></TR>"
}
$Outputreport += "</Table></BODY></HTML>"
}
$Outputreport | out-file C:\health\test.htm
##Invoke-Expression C:\temp\Scripts\Test.htm
##Send email functionality from below line, use it if you want
$smtpServer = "smtp.na.jnj.com"
$smtpFrom = "MESD1@na.jnj.com"
$smtpTo = "elazaro1@its.jnj.com"
$messageSubject = "Servers Health report ACP"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$message.Body = "<head><pre>$style</pre></head>"
$message.Body += Get-Content C:\health\test.htm
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
]
Continue reading...
Your support is highly appreciated. Thanks!
[
$ServerListFile = "C:\Ethicon.txt"
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
$Result = @()
ForEach($computername in $ServerList)
{
$AVGProc = Get-WmiObject -computername $computername win32_processor |
Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" |
Select-object @{Name = "C PercentFree"; Expression = {“{0:N2}” -f (($_.FreeSpace / $_.Capacity)*100) } }
$result += [PSCustomObject] @{
ServerName = "$computername"
CPULoad = "$($AVGProc.Average)%"
MemLoad = "$($OS.MemoryUsage)%"
CDrive = "$($vol.'C PercentFree')%"
}
1..2 | % {
$a+=[Array] $result
}
$a | out-file ".\test.txt"
##out-file -FilePath 'C:\health\test.txt'
$Outputreport = "<HTML><TITLE> Server Health Report </TITLE>
<BODY background-coloreachpuff>
<font color =""#99000"" face=""Microsoft Tai le"">
<H2> Server Health Report </H2></font>
<Table border=1 cellpadding=0 cellspacing=0>
<TR bgcolor=gray align=center>
<TD><B>Server Name</B></TD>
<TD><B>Avrg.CPU Utilization</B></TD>
<TD><B>Memory Utilization</B></TD>
<TD><B>C Drive Utilizatoin</B></TD></TR>"
Foreach($Entry in $Result)
{
if((($Entry.CpuLoad) -or ($Entry.memload)) -ge "80")
{
$Outputreport += "<TR bgcolor=red>"
}
else
{
$Outputreport += "<TR>"
}
$Outputreport += "<TD>$($Entry.Servername)</TD><TD align=center>$($Entry.CPULoad)</TD><TD align=center>$($Entry.MemLoad)</TD><TD align=center>$($Entry.Cdrive)</TD></TR>"
}
$Outputreport += "</Table></BODY></HTML>"
}
$Outputreport | out-file C:\health\test.htm
##Invoke-Expression C:\temp\Scripts\Test.htm
##Send email functionality from below line, use it if you want
$smtpServer = "smtp.na.jnj.com"
$smtpFrom = "MESD1@na.jnj.com"
$smtpTo = "elazaro1@its.jnj.com"
$messageSubject = "Servers Health report ACP"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$message.Body = "<head><pre>$style</pre></head>"
$message.Body += Get-Content C:\health\test.htm
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
]
Continue reading...