Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Health check for more than one servers

$
0
0

hello,

i found a script for health check, i ll put a fragment of it. i know how to loop with foreach command but i dont know how to insert all the datas for the same html file in different fragment. i thought i have to put each request in different fragments with incrementation, can you help me.

$servers = ("server1","server2")

function Write-HTML{

[CmdletBinding(SupportsShouldProcess=$True)]
param([Parameter(Mandatory=$false,
      ValueFromPipeline=$true)]
[string]$FilePath = "$env:USERPROFILE\desktop\Write-HTML.html",

 
$Css="<mce:style><!--
table{margin:auto; width:98%}
   Body{background-color:Orange; Text-align:Center;}
   th{background-color:black; color:white;}
   td{background-color:Grey; color:Black; Text-align:Center;}
   
--></mce:style><style _mce_bogus=><!--
table{margin:auto; width:98%}
   Body{background-color:Orange; Text-align:Center;}
   th{background-color:black; color:white;}
   td{background-color:Grey; color:Black; Text-align:Center;}
   
--></style>")
 
 foreach ($server in $servers)
 {
$Hardware = Get-WmiObject -class Win32_ComputerSystem -ComputerName $server |
 Select-Object Name,Domain,Manufacturer,Model,NumberOfLogicalProcessors,
 @{ Name = "Installed Memory (GB)" ; Expression = { "{0:N0}" -f( $_.TotalPhysicalMemory / 1gb ) } }|
 ConvertTo-Html -Fragment -As Table -PreContent "<h2>Hardware</h2>" | 
 Out-String
 }

$Report = ConvertTo-Html -Title "Servers" -Head "<h1>PowerShell Reporting<br><br>$Computername</h1><br>This report was ran: $(Get-Date)" -Body "$Hardware $Css"
 
$Report | Out-File $Filepath ; Invoke-Expression $FilePath
 
}
Write-HTML


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>