When patching operations fail with exit code 340 the root cause is probably related to the fact that your WSUS server needs a cleanup !
If the output of the patching execution activity contains the following we suggest to perform several maintenance operations.
Exception calling "GetUpdates" with "1" argument(s): "The operation has timed
At C:\Program Files\Intigua\vAgentManager\temp\Runnables\Runnables\aded2ea7-fd1
+ $allUpdates = $wsus.GetUpdates($UpdateScope) | Sort-Object -Property
Recommended Maintenance operations on WSUS
- Check if there is sufficient disk space , CPU consumption, Memory leak, connectivity checks and usual IT concerns..
- Try to reboot the WSUS Server
- run the command wsusutil.exe checkhealth and check the output to see if there are any errors.
- run the command wsusutil.exe rest and see if it fixes the issue.
If the above steps were not helpful and you are still getting exit code 340 from patch installation procedures please perform the following -
Advanced Maintenance and Optimization process for WSUS
Reject replaced Updates
Updates are accumulated on the WSUS server as time goes by, and in some cases updates are overwritten by others. This is not ideal and the purpose of the following steps is to reject replaced updates.
- Connect to your WSUS server and open the update services
- Select Updates > All updates and filter by Approval : 'Approved'
- Ctrl+A to select the filtered list of updated, right click on the classification column and select the 'Decline Button'
- Confirm the action by clicking Yes.
Wait while the updates are being declined. After that, the replaced updated will no longer appear for the computers associated to your WSUS server.
Clean unused files
Cleaning unused files will remove the files physically present on the server.
We will find in these files the replaced updates that were refused.
From the Administration Console, click Options and then click Server Cleanup Wizard.
The first step in the wizard will be to select the updates you would like to clean. Check only the 'Uneeded update files' checkbox and click next.
Once the cleaning process is completed, click on the Finish button to close the wizard. In the summary you will find the free space details.
Reindexing the database
In order to maintain optimal database performance, it is necessary to reindex the database.
A script for the following steps is available on the Technet website at this address: https://gallery.technet.microsoft.com/scriptcenter/6f8cde49-5c52-4abd-9820-f1d270ddea61
1. Start Microsoft SQL Server Management Studio and connect to the base instance where the WSUS database is running.
Note: If you are using the Windows internal database, you must install Microsoft SQL Server Management Studio on the WSUS server and use as server name :
\\.\pipe\Microsoft##WID\tsql\query using Windows authentication.
2. Right-click on SUSDB  and click on New Query .
3. Paste the script into the query box 1 and click on Run 2.
Wait while the request is being processed. Once the query is executed, the result is displayed under 
Reduce the size of the base
Always from SSMS, right click on the database SUSDB 1 then go to Tasks 2 / Reduce 3 and click on Database 4.
Click OK 1 to start the database reduction.
Once optimization is complete, the window closes automatically.