can someone help me with below
# Specify the server name(s) to check
$ctxservers = Get-ADComputer -Filter { Name -like "*app*" } | Select-Object -ExpandProperty Name
$serverNames = $ctxservers | ? { $_ -like "appusa*" }
# Specify the KB numbers of the patches you want to check
$kbNumbers = "5002197", "5002254", "5000121"
# Initialize an array to store the results
$results = @()
# Loop through each server and KB number and check if the patch is installed
foreach ($server in $serverNames) {
$resultProps = @{
Server = $server
}
foreach ($kbNumber in $kbNumbers) {
# Construct the registry path to check for the patch
$regPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*_Office16.PROPLUS*\"
if (Test-Path $regPath) {
# Get the "HelpLink" value from the registry key
$helpLink = Get-ItemProperty $regPath -Name "HelpLink" | Select-Object -ExpandProperty "HelpLink"
# Check if the "HelpLink" value contains the KB number
if ($helpLink -like "*$kbNumber*") {
$resultProps["KB$kbNumber"] = "Yes"
}
else {
$resultProps["KB$kbNumber"] = "No"
}
}
else {
$resultProps["KB$kbNumber"] = "Office installation not found"
}
}
# Add the results to the array
$result = New-Object PSObject -Property $resultProps
$results += $result
}
# Output the results in HTML format with column headers
$headerRow = "<tr><th>Server</th>"
foreach ($kb in $kbNumbers) {
$headerRow += "<th>KB$kb</th>"
}
$headerRow += "</tr>"
$html = @"
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
h2 {
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
}
table {
border-collapse: collapse;
margin: 0 auto;
}
th, td {
border: 1px solid black;
padding: 5px;
text-align: center;
}
th {
background-color: #ddd;
}
.yes {
background-color: #aaffaa;
}
.no {
background-color: #ffaaaa;
}
</style>
</head>
<body>
<h2>Office Patch Status</h2>
<table>
$headerRow
"@
foreach ($result in $results) {
$html += "<tr><td>$($result.Server)</td>"
foreach ($kb in $kbNumbers) {
$status = $result."KB$kb"
if ($status -eq "Yes") {
$class = "yes"
}
elseif ($status -eq "No") {
$class = "no"
}
else {
$class = ""
}
$html += "</tr>"
}}
$html | Out-File "office_patch_status.html" -Encoding UTF8
ii .\office_patch_status.html
The above script is for checking ms office patches on remote server. Also wanted to add dynamic output column addition capability to the script based on $kbnumbers and output should have only server and KB number columns which shows yes or No