大家早上好。我正在撰寫一個更新一組應用程式的腳本,我正在嘗試制作一個 HTML 表格以進行驗證。這個評論是我的框架
https://www.reddit.com/r/PowerShell/comments/3zai30/html_report_from_multiple_arrays/cyl9k47/?utm_source=share&utm_medium=ios_app&utm_name=iossmf&context=3
它在大多數情況下效果很好。但它是基于整數構建的,所以如果我有一個應用程式無法安裝/更新,它會弄亂專案的位置。我正在尋找一些洞察力,使其更像是一個靜態表,因此如果應用程式無法安裝/更新,它只是一個空行。
Function Get-Verification{
$Header = '<style>
body {
background-color: Gainsboro;
font-family: "Calibri";
}
table {
border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
width: 75%;
}
th {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: black;
background-color: #98C6F3;
}
td {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: black;
background-color: White;
}
tr {
text-align: left;
}
</style>'
[System.Collections.ArrayList]$SoftwareNames = @(
"Notepad ",
"PowerShell7",
"RACTools",
"Rufus",
"RuTTY",
"WinSCP",
"WireShark",
"Microsoft Edge",
"Chrome Portable",
"FireFox Portable",
"NetBanner",
"OVFTool",
"PowerCLI",
"VMRC",
"Workstation",
"Axway",
"InstallRoot",
"ActivClient",
"90Meter",
"Microsoft Office"
)
[System.Collections.ArrayList]$NewSWVersions = @(
"$NotepadVersion",
"$PowerShellVersion",
"$RACToolsVersion",
"$RufusVersion",
"$RuTTYVersion",
"$WinSCPVersion",
"$WireSharkVersion",
"$MSEdgeVersion",
"$ChromeVersion",
"$FireFoxVersion",
"$NetBannerVersion",
"$OVFToolMsiVersion",
"$PowerCLIVersion",
"$VMRCVersion",
"$WorkstationVersion",
"$AxwayVersion",
"$InstallRootMsi",
"$ACVersion",
"$90MVersion",
"$Office" #Needs fixing
)
[System.Collections.ArrayList]$InstalledVersions = @(
"$NotepadExe",
"$PowerShellExe",
"$RACToolsExe",
"$RufusVersion",
"$RuTTYExe",
"$WinSCPExe",
"$WireSharkExe",
"$MSEdgeExe",
"$ChromeVersion",
"$FireFoxVersion",
"$NetBannerExe",
"$OVFToolExe",
"$PowerCLIModule",
"$VMRCExe",
"$WorkstationExe",
"$AxwayExe",
"$InstallRootExe",
"$ACExe",
"$90MExe",
"$Office" #needs fixing
)
If($Class -eq "NIPR"){
$SoftwareNames.Remove("90Meter")
$NewSWVersions.Remove("$90MVersion")
$InstalledVersions.Remove("$90MExe")
}
If($Class -eq "SIPR"){
$SoftwareNames.Remove("ActivClient")
$NewSWVersions.Remove("$ACVersion")
$InstalledVersions.Remove("$ACExe")
}
$i = 0
$(
While (
@(
$SoftwareNames[$i],
$NewSWVersions[$i],
$InstalledVersions[$i]
) -ne $null
) {
$Properties = [ordered]@{
"Software Names" = $SoftwareNames[$i]
"Expected Version" = $NewSWVersions[$i]
"Installed Version" = $InstalledVersions[$i]
}
New-Object psobject -Property $Properties
$i
}
) | ConvertTo-Html -head $Header -PostContent "Report Run on $Date"| Out-File "App_Verification.htm"
invoke-item "App_Verification.htm"
exit
}
我正在提交的資訊是應用程式名稱預期版本安裝版本
它們都是帶有提取所需資訊的變數的陣列。
uj5u.com熱心網友回復:
使用有序字典來存盤資訊而不是單獨的陣列:
$software = [ordered]@{
"Notepad " = [pscustomobject]@{
Application = "Notepad "
NewVersion = "$NotepadVersion"
InstalledVersion = "$NotepadExe"
}
"PowerShell7" = [pscustomobject]@{
Application = "PowerShell7"
NewVersion = "$PowerShellVersion"
InstalledVersion = "$PowerShellExe"
}
# ... and so on
}
從串列中洗掉應用程式然后變為:
If($Class -eq "NIPR"){
# remove the whole object from the dictionary, no need to worry about multiple collections
$software.Remove("90Meter")
}
修改一個的細節只是通過名稱參考它并修改正確的屬性:
$software['PowerShell7'].NewVersion = "new version goes here"
由于它們現在已經是物件,因此將它們匯出為 HTML 非常簡單:
$software.Values |ConvertTo-Html ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/338516.html
