You have a slight problem because there is no $result variable. That doesn't matter because even if you use the $Updates variable, you still have the same problem. I found that your code works for me on Win10, but fails on my Win11 22H2 laptop.
To query update history you can use this code.
$UpdateSession = New-Object -ComObject 'Microsoft.Update.Session'
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$UpdateSearcher.QueryHistory(0,100) | format-table -Property ResultCode, Date, Title
You can also use the PSWindowsUpdate module. Here is what I use.
# Install-Module -Name PSWindowsUpdate # run this to install it
Get-WUHistory -Last 100 | where-object -Property Title -notlike "Security Intelligence Update*" | format-list -Property Result, Date, Title
Note that Get-WUHistory hangs for me if I don't limit the search with a -Last parameter.