合并两个HTML文件输出,其中还包含单个HTML文件中的表(比较表格式)

发布于 2025-01-22 06:30:43 字数 5984 浏览 0 评论 0原文

我有两个HTML文件,其中包含VM信息,例如OS详细信息,内存,网络详细信息等,以表格格式进行迁移和迁移。 对于最终分析,我需要以比较表格式中的HTML文件中的组合报告 例如。 我想要此格式的最终

​​文件pre_migration_detailspost_migration_detailsany_change(是/否)
OS
内存
网络,

例如它将比较并在任何_change列中给出是或否 我为前报告和发布报告创建的脚本如下

$header = @"
<style>

    h1 {

        font-family: Arial, Helvetica, sans-serif;
        color: #e68a00;
        font-size: 28px;

    }

    
    h2 {

        font-family: Arial, Helvetica, sans-serif;
        color: #000099;
        font-size: 16px;

    }

    
    
   table {
        font-size: 12px;
        border: 0px; 
        font-family: Arial, Helvetica, sans-serif;
    } 
    
    td {
        padding: 4px;
        margin: 0px;
        border: 0;
    }
    
    th {
        background: #395870;
        background: linear-gradient(#49708f, #293f50);
        color: #fff;
        font-size: 11px;
        text-transform: uppercase;
        padding: 10px 15px;
        vertical-align: middle;
    }

    tbody tr:nth-child(even) {
        background: #f0f0f2;
    }

        #CreationDate {

        font-family: Arial, Helvetica, sans-serif;
        color: #ff3300;
        font-size: 12px;

    }
    .StopStatus {

        color: #ff0000;
    }
    
  
    .RunningStatus {

        color: #008000;
    }
    



</style>
"@
$complist = Get-Content .\Documents\abc.txt
#$path="C:\Users\prameshp\documents\$comp result2.html "
$OutputMessage = @()
$ServicesInfo=@()

foreach($comp in $complist)
{ 
 
    $pingtest = Test-Connection -ComputerName $comp -Count 4 -ErrorAction SilentlyContinue

    if($pingtest) {
         $OutputMessage += "$comp is Online"
         Write-Host "$comp,Online" -ForegroundColor Green

#The command below will get the name of the computer
$ComputerName = "<h1>Pre Migration Check : $env:computername</h1>"

#hostname

$namehost= "<h2>Host Name </h2>$comp" 

#The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable
$OSinfo = Get-WmiObject Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "<h2>Operating System Information</h2>"

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-WmiObject Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "<h2>Processor Information</h2>"

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-WmiObject -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "<h2>BIOS Information</h2>"

#ping result
$ping=ping $comp 
$pingresult = "<h2>Ping Result</h2>$ping"  
                              
#get services
Write-Verbose -Message "Getting Services"
$total=(Get-WmiObject Win32_Service -ComputerName $comp).count
$Running=(Get-WmiObject Win32_Service -ComputerName $comp | Where-Object {$_.State -eq 'Running'}).count 
$Stopped=(Get-WmiObject Win32_Service -ComputerName $comp | Where-Object {$_.State -eq 'Stopped'}).count 
$ServicesInfo1=New-Object -TypeName PSObject -Property @{
                                TotalServices = $total     
                                Running = $Running
                                Stopped= $Stopped
                                } | ConvertTo-Html -As List -Fragment -PreContent "<h2>Services Information</h2>"
$ServicesInfo =Get-WmiObject Win32_Service -ComputerName $comp| select Name,State,StartMode,StartName |Sort-Object StartMode | ConvertTo-Html -Fragment -PreContent "<h2>Services</h2>"
$ServicesInfo = $ServicesInfo -replace '<td>Running</td>','<td class="RunningStatus">Running</td>'
$ServicesInfo = $ServicesInfo -replace '<td>Stopped</td>','<td class="StopStatus">Stopped</td>'

#get memory details
Write-Verbose "Querying Memory Details"
$memory=Get-WmiObject win32_logicaldisk -Filter "deviceid='C:'" -ComputerName $comp |
select PSComputername ,Caption ,
@{Name="SizeGB";Expression={($_.Size/1gb) -as [int]}},
@{Name="FreeGB";Expression={($_.Freespace/1gb).Tostring("#.##") }},
@{Name="PercentFree";Expression={(($_.Freespace/$_.Size)*100).Tostring("#.##") }} | ConvertTo-Html -As List -Fragment -PreContent "<h2>Disk Utilization</h2>"

#get Network details
#$cim = New-CimSession -ComputerName $comp
$network=Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $comp -Filter "IPEnabled='True'"| 
    Select-Object PSComputerName, 
        @{Name='IpAddress';Expression={$_.IpAddress -join '; '}}, 
        @{Name='IpSubnet';Expression={$_.IpSubnet -join '; '}}, 
        @{Name='DefaultIPgateway';Expression={$_.DefaultIPgateway -join '; '}}, 
        @{Name='DNSServerSearchOrder';Expression={$_.DNSServerSearchOrder -join '; '}},DHCPEnabled,MACAddress | ConvertTo-Html -As List -Fragment -PreContent "<h2>Network Information</h2>"
       

#Create the HTML document
ConvertTo-HTML -Head $header -Body "$ComputerName$namehost$OSinfo$ProcessInfo$BiosInfo$memory$network$pingresult$ServicesInfo1$ServicesInfo" -PostContent "<i>report generated: $(Get-Date)</i>" |
Out-File -FilePath C:\Users\prameshp\documents\Report45.html
$fragments=@()
      }
     else {
   
       $OutputMessage += "$comp is Offline"
       Write-Host "$comp,offline" -ForegroundColor Red
          
          }
 }
 
   Write-Host "####task completed####" 

I have two html files containing vm information like os details, memory, network details etc. in table format for pre and post migration.
For final analysis I need combine report in html file in comparison table format
for eg.
I want final file in this format

itempre_migration_detailspost_migration_detailsany_change(yes/no)
os
memory
network

Like it will compare and give yes or no in any_change column also
script that I have created for pre and post report is as follows

$header = @"
<style>

    h1 {

        font-family: Arial, Helvetica, sans-serif;
        color: #e68a00;
        font-size: 28px;

    }

    
    h2 {

        font-family: Arial, Helvetica, sans-serif;
        color: #000099;
        font-size: 16px;

    }

    
    
   table {
        font-size: 12px;
        border: 0px; 
        font-family: Arial, Helvetica, sans-serif;
    } 
    
    td {
        padding: 4px;
        margin: 0px;
        border: 0;
    }
    
    th {
        background: #395870;
        background: linear-gradient(#49708f, #293f50);
        color: #fff;
        font-size: 11px;
        text-transform: uppercase;
        padding: 10px 15px;
        vertical-align: middle;
    }

    tbody tr:nth-child(even) {
        background: #f0f0f2;
    }

        #CreationDate {

        font-family: Arial, Helvetica, sans-serif;
        color: #ff3300;
        font-size: 12px;

    }
    .StopStatus {

        color: #ff0000;
    }
    
  
    .RunningStatus {

        color: #008000;
    }
    



</style>
"@
$complist = Get-Content .\Documents\abc.txt
#$path="C:\Users\prameshp\documents\$comp result2.html "
$OutputMessage = @()
$ServicesInfo=@()

foreach($comp in $complist)
{ 
 
    $pingtest = Test-Connection -ComputerName $comp -Count 4 -ErrorAction SilentlyContinue

    if($pingtest) {
         $OutputMessage += "$comp is Online"
         Write-Host "$comp,Online" -ForegroundColor Green

#The command below will get the name of the computer
$ComputerName = "<h1>Pre Migration Check : $env:computername</h1>"

#hostname

$namehost= "<h2>Host Name </h2>$comp" 

#The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable
$OSinfo = Get-WmiObject Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "<h2>Operating System Information</h2>"

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-WmiObject Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "<h2>Processor Information</h2>"

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-WmiObject -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "<h2>BIOS Information</h2>"

#ping result
$ping=ping $comp 
$pingresult = "<h2>Ping Result</h2>$ping"  
                              
#get services
Write-Verbose -Message "Getting Services"
$total=(Get-WmiObject Win32_Service -ComputerName $comp).count
$Running=(Get-WmiObject Win32_Service -ComputerName $comp | Where-Object {$_.State -eq 'Running'}).count 
$Stopped=(Get-WmiObject Win32_Service -ComputerName $comp | Where-Object {$_.State -eq 'Stopped'}).count 
$ServicesInfo1=New-Object -TypeName PSObject -Property @{
                                TotalServices = $total     
                                Running = $Running
                                Stopped= $Stopped
                                } | ConvertTo-Html -As List -Fragment -PreContent "<h2>Services Information</h2>"
$ServicesInfo =Get-WmiObject Win32_Service -ComputerName $comp| select Name,State,StartMode,StartName |Sort-Object StartMode | ConvertTo-Html -Fragment -PreContent "<h2>Services</h2>"
$ServicesInfo = $ServicesInfo -replace '<td>Running</td>','<td class="RunningStatus">Running</td>'
$ServicesInfo = $ServicesInfo -replace '<td>Stopped</td>','<td class="StopStatus">Stopped</td>'

#get memory details
Write-Verbose "Querying Memory Details"
$memory=Get-WmiObject win32_logicaldisk -Filter "deviceid='C:'" -ComputerName $comp |
select PSComputername ,Caption ,
@{Name="SizeGB";Expression={($_.Size/1gb) -as [int]}},
@{Name="FreeGB";Expression={($_.Freespace/1gb).Tostring("#.##") }},
@{Name="PercentFree";Expression={(($_.Freespace/$_.Size)*100).Tostring("#.##") }} | ConvertTo-Html -As List -Fragment -PreContent "<h2>Disk Utilization</h2>"

#get Network details
#$cim = New-CimSession -ComputerName $comp
$network=Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $comp -Filter "IPEnabled='True'"| 
    Select-Object PSComputerName, 
        @{Name='IpAddress';Expression={$_.IpAddress -join '; '}}, 
        @{Name='IpSubnet';Expression={$_.IpSubnet -join '; '}}, 
        @{Name='DefaultIPgateway';Expression={$_.DefaultIPgateway -join '; '}}, 
        @{Name='DNSServerSearchOrder';Expression={$_.DNSServerSearchOrder -join '; '}},DHCPEnabled,MACAddress | ConvertTo-Html -As List -Fragment -PreContent "<h2>Network Information</h2>"
       

#Create the HTML document
ConvertTo-HTML -Head $header -Body "$ComputerName$namehost$OSinfo$ProcessInfo$BiosInfo$memory$network$pingresult$ServicesInfo1$ServicesInfo" -PostContent "<i>report generated: $(Get-Date)</i>" |
Out-File -FilePath C:\Users\prameshp\documents\Report45.html
$fragments=@()
      }
     else {
   
       $OutputMessage += "$comp is Offline"
       Write-Host "$comp,offline" -ForegroundColor Red
          
          }
 }
 
   Write-Host "####task completed####" 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文