Powershell Correct Output Until It Gets Added to an HTML Report -
i trying edit report emailed our server on schedule. added logsize , logsize2. added html report when gets emailed comes "microsoft.powershell.commands.genericmeasureinfo". works intended when run without rest of report.
foreach ($computer in $computers) { $diskinfo= get-wmiobject -computername $computer win32_logicaldisk | where-object{$_.drivetype -eq 3} | where-object{ ($_.freespace/$_.size)*100 -lt $thresholdspace} | select-object systemname, drivetype, volumename, name, @{n='size (gb)';e={"{0:n2}" -f ($_.size/1gb)}}, @{n='freespace (gb)';e={"{0:n2}" -f ($_.freespace/1gb)}}, @{n='percentfree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} | convertto-html -fragment $logsize= get-childitem "c:\windows\logs\cbs\" -force -recurse | measure-object -property length -sum "{0:n2}" -f ($logsize.sum/ 1mb) + "mb of cbs logs" | out-string $logsize2= get-childitem "c:\programdata\symantec\symantec endpoint protection\12.1.5337.5000.105\data\install\logs\" -force -recurse | measure-object -property length -sum "{0:n2}" -f ($logsize2.sum/ 1mb) + "mb of symantec logs" | out-string #region system info $os = (get-wmiobject win32_operatingsystem -computername $computer).caption $systeminfo = get-wmiobject -class win32_operatingsystem -computername $computer | select-object name, totalvisiblememorysize, freephysicalmemory $totalram = $systeminfo.totalvisiblememorysize/1mb $freeram = $systeminfo.freephysicalmemory/1mb $usedram = $totalram - $freeram $rampercentfree = ($freeram / $totalram) * 100 $totalram = [math]::round($totalram, 2) $freeram = [math]::round($freeram, 2) $usedram = [math]::round($usedram, 2) $rampercentfree = [math]::round($rampercentfree, 2) #endregion $topprocesses = get-process -computername $computer | sort ws -descending | select processname, id, ws -first $proccessnumtofetch | convertto-html -fragment #region services report $servicesreport = @() $services = get-wmiobject -class win32_service -computername $computer | {($_.startmode -eq "auto") -and ($_.state -eq "stopped")} foreach ($service in $services) { $row = new-object -type psobject -property @{ name = $service.name status = $service.state startmode = $service.startmode } $servicesreport += $row } $servicesreport = $servicesreport | convertto-html -fragment #endregion #region event logs report $systemeventsreport = @() $systemevents = get-eventlog -computername $computer -logname system -entrytype error,warning -newest $eventnum foreach ($event in $systemevents) { $row = new-object -type psobject -property @{ timegenerated = $event.timegenerated entrytype = $event.entrytype source = $event.source message = $event.message } $systemeventsreport += $row } $systemeventsreport = $systemeventsreport | convertto-html -fragment $applicationeventsreport = @() $applicationevents = get-eventlog -computername $computer -logname application -entrytype error,warning -newest $eventnum foreach ($event in $applicationevents) { $row = new-object -type psobject -property @{ timegenerated = $event.timegenerated entrytype = $event.entrytype source = $event.source message = $event.message } $applicationeventsreport += $row } $applicationeventsreport = $applicationeventsreport | convertto-html -fragment #endregion # create chart using our chart function create-piechart -filename ((get-location).path + "\chart-$computer") $freeram, $usedram $listofattachments += "chart-$computer.png" #region uptime # fetch uptime of current system using our get-hostuptime function. $systemuptime = get-hostuptime -computername $computer #endregion # create html report current system being looped through $currentsystemhtml = @" <hr noshade size=3 width="100%"> <div id="report"> <p><h2>$computer report</p></h2> <h3>system info</h3> <table class="list"> <tr> <td>system uptime</td> <td>$systemuptime</td> </tr> <tr> <td>os</td> <td>$os</td> </tr> <tr> <td>total ram (gb)</td> <td>$totalram</td> </tr> <tr> <td>free ram (gb)</td> <td>$freeram</td> </tr> <tr> <td>percent free ram</td> <td>$rampercentfree</td> </tr> </table> <img src="chart-$computer.png" alt="$computer chart"> <h3>disk info</h3> <table class="normal">$diskinfo</table> <br></br> <p>$logsize</p> <p>$logsize2</p> <br></br> <div class="first column"> <h3>system processes - top $proccessnumtofetch highest memory usage</h3> <p>the following $proccessnumtofetch processes consuming highest amount of working set (ws) memory (bytes) on $computer</p> <table class="normal">$topprocesses</table> </div> <div class="second column"> <h3>system services - automatic startup not running</h3> <p>the following services set automatic startup type, yet not running on $computer</p> <table class="normal"> $servicesreport </table> </div> <h3>events report - last $eventnum system/application log events warnings or errors</h3> <p>the following list of last $eventnum <b>system log</b> events had event type of either warning or error on $computer</p> <table class="normal">$systemeventsreport</table> <p>the following list of last $eventnum <b>application log</b> events had event type of either warning or error on $computer</p> <table class="normal">$applicationeventsreport</table>
put 1 of these
$logsize=
in front of this
"{0:n2}" -f ($logsize.sum/ 1mb) + "mb of cbs logs" | out-string
and same logsize2 end result this
$logsize= get-childitem "c:\windows\logs\cbs\" -force -recurse | measure-object -property length -sum $logsize= "{0:n2}" -f ($logsize.sum/ 1mb) + "mb of cbs logs" | out-string $logsize $logsize2= get-childitem "c:\programdata\symantec\symantec endpoint protection\12.1.5337.5000.105\data\install\logs\" -force -recurse | measure-object -property length -sum $logsize2= "{0:n2}" -f ($logsize2.sum/ 1mb) + "mb of symantec logs" | out-string $logsize2
Comments
Post a Comment