合并两个HTML文件输出,其中还包含单个HTML文件中的表(比较表格式)
我有两个HTML文件,其中包含VM信息,例如OS详细信息,内存,网络详细信息等,以表格格式进行迁移和迁移。 对于最终分析,我需要以比较表格式中的HTML文件中的组合报告 例如。 我想要此格式的最终
文件 | pre_migration_details | post_migration_details | any_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
item | pre_migration_details | post_migration_details | any_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论