HTML报告的标题默认为报告的底部
我有一个脚本,可以提取DHCP统计信息(范围、范围ID、范围选项等)并输出到HTML报告,当它输出到报告时,报告的标题默认位于底部,我无法确定格式错误在哪里HTML报告的标题默认为报告的底部,html,powershell,Html,Powershell,我有一个脚本,可以提取DHCP统计信息(范围、范围ID、范围选项等)并输出到HTML报告,当它输出到报告时,报告的标题默认位于底部,我无法确定格式错误在哪里 $Target = '########' #$Title= "<p>Test Title</p>" $Path = '##################################\' $Name = 'Test3.html' $TestO = @()
$Target = '########'
#$Title= "<p>Test Title</p>"
$Path = '##################################\'
$Name = 'Test3.html'
$TestO = @()
$ScopeIDs = Get-DhcpServerv4Scope -ComputerName $Target | Select "Name","SubnetMask","StartRange","EndRange","ScopeID","State"
$ScopeOut = $ScopeIDs | ConvertTo-Html -As Table | Out-String | Out-File -FilePath $Path$Name
#$Head = "<h2>Error reporting for #########</h2>"
$Header = @"
<style>
TABLE {border-width: 1px: border-style: solid; border-color: black; border-collaspe: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
ForEach ($ScopeID in $ScopeIDs){ $TestO +=
$ScopeStat = Get-DhcpServerv4ScopeStatistics -ComputerName $Target -ScopeId $ScopeID.ScopeID | Select "ScopeID", "Free","InUse","PercentageInUse" | ConvertTo-Html -As Table | Out-String | Out-File -FilePath $Path$Name -Append
$OptValue = Get-DhcpServerv4OptionValue -ComputerName $Target -ScopeId $ScopeID.ScopeId -All | Select-Object Name,OptionId,Type,@{Name="Value";Expression={$_.Value}} | ConvertTo-Html -As Table | Out-String | Out-File -FilePath $Path$Name -Append
}
$Body = $ScopeStat + $OptValue
ConvertTo-Html -PreContent "<h1>Test</h1>" -Head $Header -Body $Body | Out-File $Path$Name -Append
$Target='
#$Title=“测试标题”
$Path=''
$Name='Test3.html'
$TestO=@()
$ScopeIDs=Get-DhcpServerv4Scope-ComputerName$Target |选择“名称”、“子网掩码”、“开始传输”、“结束范围”、“ScopeID”、“状态”
$ScopeOut=$ScopeIDs |转换为Html-As表| Out字符串| Out文件-FilePath$Path$Name
#$Head=“针对########的错误报告”
$Header=@“
表{边框宽度:1px:边框样式:实心;边框颜色:黑色;边框折叠:折叠;}
TH{边框宽度:1px;填充:3px;边框样式:纯色;边框颜色:黑色;背景颜色:#6495ED}
TD{边框宽度:1px;填充:3px;边框样式:纯色;边框颜色:黑色;}
"@
ForEach($ScopeID中的ScopeID){$TestO+=
$ScopeStat=Get-DhcpServerv4ScopeStatistics-ComputerName$Target-ScopeId$ScopeId.ScopeId |选择“ScopeId”、“Free”、“InUse”、“PercentageInUse”|转换为Html-作为表|输出字符串|输出文件-文件路径$Path$Name-追加
$OptValue=Get-DhcpServerv4OptionValue-ComputerName$Target-ScopeId$ScopeId.ScopeId-All |选择对象名,OptionId,Type,@{Name=“Value”;Expression={$\值}}}|转换为Html-As Table | Out String | Out File-FilePath$Path$Name-Append
}
$Body=$ScopeStat+$OptValue
转换为Html-预内容“测试”-Head$Header-Body$Body | Out File$Path$Name-Append
我将重新格式化您的样本,将长管道分解为更小的块:
foreach( $ScopeID in $ScopeIDs )
{
$ScopeStat = Get-DhcpServerv4ScopeStatistics -ComputerName $Target -ScopeId $ScopeID.ScopeID `
| Select "ScopeID", "Free","InUse","PercentageInUse" `
| ConvertTo-Html -As Table `
| Out-String `
| Out-File -FilePath $Path$Name -Append
$OptValue = Get-DhcpServerv4OptionValue -ComputerName $Target -ScopeId $ScopeID.ScopeId -All `
| Select-Object Name,OptionId,Type,@{Name="Value";Expression={$_.Value}} `
| ConvertTo-Html -As Table `
| Out-String `
| Out-File -FilePath $Path$Name -Append
}
$Body = $ScopeStat + $OptValue
ConvertTo-Html -PreContent "<h1>Test</h1>" -Head $Header -Body $Body `
| Out-File $Path$Name -Append
示例屏幕截图中的标题在哪里?看起来您正在使用-Append标记附加到现有文件上。所以html被添加到了文件的末尾。当-append-at-end被删除时,数据不会被填充。这就像一个符咒,我只需要更改scopeID变量的格式并退出比赛,谢谢!
Add-Content -Path $Path$Name -Value "<html>";
Add-Content -Path $Path$Name -Value $Header;
Add-Content -Path $Path$Name -Value "<h1>Test</h1>";
foreach( $ScopeID in $ScopeIDs )
{
$table = Get-DhcpServerv4ScopeStatistics -ComputerName $Target -ScopeId $ScopeID.ScopeID `
| Select "ScopeID", "Free","InUse","PercentageInUse" `
| ConvertTo-Html -As Table -Fragment
Add-Content -Path $Path$Name -Value $table
$table = Get-DhcpServerv4OptionValue -ComputerName $Target -ScopeId $ScopeID.ScopeId -All `
| Select-Object Name,OptionId,Type,@{Name="Value";Expression={$_.Value}} `
| ConvertTo-Html -As Table -Fragment
Add-Content -Path $Path$Name -Value $table
}
Add-Content -Path $Path$Name "</html>";