Managing and deploying updates via Configuration Manager
That is quite common code but I remember I have delt with with many times when the scan job goes timeout because of the WSUS database bloat. Consider to clean and maintain your SUSDB. Look for this: https://learn.microsoft.com/en-us/troubleshoot/mem/configmgr/wsus-maintenance-guide