I wrote a little tool based on code here that allows you to search a computer for software and display their versions in a table down below. It works fine but it retains the table data. I need it so if a new user loads the site, it starts fresh without a table showing or any data. I’ve tried variations of Clear-UDElement and clearing the variable itself.
Here is the code:
$Page4 = New-UDPage -Name "GetVer" -Title "GetVer" -Icon search -Content {
New-UDInput -SubmitText "Search" -Title "Search for installed software" -Endpoint {
param(
[Parameter(Mandatory, HelpMessage = "Computer name")]
[string]$ComputerName,
[Parameter(Mandatory, HelpMessage = "Software")]
[string]$software
)
$a = Get-CimInstance -computername $ComputerName -Class Win32_Product
$Cache:Found = $a | Where-Object Name -like "*$software*" -erroraction stop
Sync-UDElement -Id 'results'
}
New-UDElement -Id 'results' -Tag 'div' -Endpoint {
if ($Cache:Found -ne $null) {
New-UDTable -Id 'results' -Title "Software found" -Header @("name", "version") -Endpoint {
$Cache:Found | Out-UDTableData -Property @("name", "version")
}
}
}
}