I did something similar for a customer a couple of years ago. In this case we created a custom table to record the systems we'd deleted and then did the delete. We used the ItemtoDelete table for the deletion rather than trying to run the delete stored procedure as if my memory serves me right this takes care of all the clean up
There was a query which ran as an automation policy to select the computers and the results of this were then put into a task which did the 'delete'. Query in task was as below
-- This put the details we wanted to record for deleted computers in the custom table
Insert into Custom_Computers_Auto_Deleted Values ('%!Guid!%','%!Name!%','%!Domain!%','%!IP Address!%', '%!Asset Tag!%', '%!Model!%', '%!Last Logon User!%','%!Last Inventory Received!%','%!Ad Last Logon!%','%!Date Deleted!%')
-- This then added the systems to the OOB ItemToDelete table which would then delete them
Insert into ItemToDelete Values ('%!Guid!%', Dateadd(dd,-1,Getdate()))
Hope this helps
Original Message:
Sent: Jan 07, 2022 11:39 AM
From: DANY LAVOIE
Subject: Programmatically delete computer
We would like to daily delete computer who are being mark as retired. We don't want to wait XX months and use the purging maintenance.
Is it ok to delete a computer by using the stored procedure spResourceDelete (spResourceDeleteBulk)?
this way, I'll write and SQL query to delete computers who are being marked as retired by technician.
Thanks!!