繁体   English   中英

Powershell校正输出,直到将其添加到HTML报表中为止

[英]Powershell Correct Output Until It Gets Added to an HTML Report

我正在尝试编辑从服务器按时间表发送的报告。 我添加了LogSize和Logsize2。 我将其添加到html报告中,但是当通过电子邮件发送给它时,它又返回为“ Microsoft.PowerShell.Commands.GenericMeasureInfo”。 当我在没有其余报告的情况下运行它时,它按预期工作。

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 | Where {($_.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 the chart using our Chart Function
Create-PieChart -FileName ((Get-Location).Path + "\chart-$computer") $FreeRAM, $UsedRAM
$ListOfAttachments += "chart-$computer.png"
#region Uptime
# Fetch the Uptime of the current system using our Get-HostUptime Function.
$SystemUptime = Get-HostUptime -ComputerName $computer
#endregion

# Create HTML Report for the 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 are those consuming the 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 but not Running</h3>
<p>The following services are those which are set to Automatic startup type, yet are currently not running on $computer</p>
<table class="normal">
$ServicesReport
</table>
</div>

<h3>Events Report - The last $EventNum System/Application Log Events that were Warnings or Errors</h3>
<p>The following is a list of the last $EventNum <b>System log</b> events that had an Event Type of either Warning or Error on $computer</p>
<table class="normal">$SystemEventsReport</table>

<p>The following is a list of the last $EventNum <b>Application log</b> events that had an Event Type of either Warning or Error on $computer</p>
<table class="normal">$ApplicationEventsReport</table>

放另一个

$LogSize= 

在此之前

"{0:N2}" -f ($LogSize.sum/ 1mb) + "MB of CBS Logs" | out-string

并对LogSize2进行相同操作,因此最终结果可能如下所示

$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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM