OpsMgr : Agent Deployment Error; Already in the process of being managed

Came across this error recently when trying to push the agent using discovery wizard:

One or more computers you are trying to manage are already in the process of being managed

From SCOM OPS SQL Database use the following TSQL to resolve this issue:

{code lang:sql showtitle:false lines:false hidden:false}USE OperationsManager
GO

SELECT AgentPendingActionId, AgentName
FROM AgentPendingAction
WHERE AgentName like ‘ServerName%’

–As long as the above returns something useful, then run

DECLARE @ActionId uniqueidentifier
SET @ActionId =
(
SELECT AgentPendingActionId
FROM AgentPendingAction
WHERE AgentName like ‘ServerName%’
)
EXEC p_AgentPendingActionDeleteByIdList @AgentPendingActionIdList = @ActionId{/code}