Hello everyone!
I am trying to return the results from a function to a table but when I run the dashboard it always returns empty.
Here is the function:
Function Get-PSWMissingUpdate {
param($ComputerName)
}
Import-Module POSHWSUS -Verbose
$connectPSWSUSServerSplat = @{
WsusServer = 'wsus'
Port = 8531
SecureConnection = $true
Verbose = $true
}
Connect-PSWSUSServer @connectPSWSUSServerSplat | out-null
$getPSWSUSUpdatePerClientSplat = @{
ComputerName = $ComputerName
}
$whereObjectSplat = @{
FilterScript = { $_.UpdateInstallationState -ne "NotApplicable" -and $_.UpdateInstallationState -ne "Installed" -and $_.UpdateInstallationState -ne "Unknown" }
}
$s = (Get-PSWSUSUpdatePerClient @getPSWSUSUpdatePerClientSplat | Where-Object @whereObjectSplat)
$wu = $s.getUpdate()
$updates = $s
$results = foreach ($w in $wu) {
foreach ($u in $updates) {
if ($w.updateid -eq $u.UpdateId.Guid) {
[PSCustomObject]@{
Title = $w.Title
MsrcSeverity = $w.MsrcSeverity
KnowledgebaseArticles = $w.KnowledgebaseArticles[0]
AdditionalInformationUrls = $w.AdditionalInformationUrls[0]
UpdateClassificationTitle = $w.UpdateClassificationTitle
CreationDate = $w.CreationDate
ArrivalDate = $w.ArrivalDate
IsApproved = $w.IsApproved
IsDeclined = $w.IsDeclined
UpdateInstallationState = $u.UpdateInstallationState
}
}
}
}
return $results
}
Endpoint initialization:
$EndpointInitparams = @{
Module = "PoshWSUS"
Function = "Get-PSWMissingUpdate"
Variable = "pswmissingupdate"
}
dashboard:
$Session:PSWMissingUpdate = Get-PSWMissingUpdate -ComputerName $Session:Computer
Wait-Debugger
1000
if ($Session:PSWMissingUpdate.count -gt 0) {
Show-UDModal -Content {
$ISGridParams = @{
Id = "WindowsUpdates"
Title = "Windows Updates"
ArgumentList = $Session:Computer
Headers = @("Title")
Properties = @("Title")
PageSize = 100
ServerSideProcessing = $false
}
New-UDGrid @ISGridParams -Endpoint {
$Session:pswmissingupdate | Select-Object Title | Out-UDGridData
}
Inside the runspace:
[DBG]: [Process:4532]: [GetUpdatesSoftware]: PS C:\Users\username>> $Session.SessionVariables
Key Value
--- -----
pswmissingupdate
The funny thing is that if I run the commands from the function one by one inside the runspace I get the results.
PSVersion 5.1.14409.1018
Universal dashaord 2.9.0
What I am missing?
Cheers