I have a cleanupscript which I run daily to fix this kind of issues. In order to remove data from removed servers, run this:
Make sure you delete the errorhistory also:
delete
from [policy].[PolicyHistory]
where evaluatedServer not in
(
SELECT server_name
FROM [policy].[pfn_ServerGroupInstances]('')
)
NOTE: policyhistorydetail will be deleted automatically because of a foreign key constraint. This may generate a lot of logging at first run.Make sure you delete the errorhistory also:
delete
from [policy].[EvaluationErrorHistory]
where evaluatedServer not in
(
SELECT server_name
FROM [policy].[pfn_ServerGroupInstances]('')
)