$Cache randomly clears values from PSObject

Product: PowerShell Universal Dashboard
Version: 1.5.8

I am basically pulling down some info from AD and for some reason “OperatingSystem” values keep disappearing.
As I refresh the cached variable, half the time it works, the other half the time OperatingSystem variable goes immediately null for all computer objects. At first I though there’s some kind of restriction coming from AD, but I could not replicate this problem in my own PS console even while spamming the command like crazy.

Then I refreshed the cache variable again, made sure it works ok, came back 6 minutes later and all OperatingSystem values were null.

One important thing to note here is that I am copying PSObject as I am setting cache variable. For some reason I cannot set the $cache variable directly, it immediately becomes $null (the whole thing). I am guesing this is something to do with Object reference being deleted so the variable gets deleted or something along those lines?

I tried converting to and from json object as a means of cloning PSObject, but it takes so long, the application just times out, where copying is almost instant, but could also be the culprit (see below code)

I was hoping someone would have some insight on this before I scrap $Cache scope altogether for PSObjects.

Any ideas?

Import-Module -Name ActiveDirectory

$Cache:ADComputers = $null
$err = $false
$errMsg = “”

try {
$query = Get-ADComputer -Filter * -Properties @(“enabled”,“description”,“lastLogon”,“lastLogonTimestamp”,“logonCount”,“operatingSystem”,“whenCreated”)
catch {
$err = $true
$errMsg = ($error[0].Exception.Message)
Show-UDToast -Message $errMsg

Show-UDToast -Message “Cached $($query.Computers.name.count) AD Computers”

$Cache:ADComputersData = if ($err) {@()} else {$query.Computers.PSObject.Copy()}
$Cache:ADComputersError = $err
$Cache:ADComputersErrorMessage = $errMsg
$Cache:ADComputersCacheDate = (Get-date)