Hello @Vinicius Santos
I would start recommending from the official article: https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/troubleshoot-onboarding?view=o365-worldwide
Check the service health (sc query sense command). Make sure it's not in an intermediate state ('Pending_Stopped', 'Pending_Running') and try to run the script again (with administrator rights).
If the device is running Windows 10, version 1607 and running the command sc query sense returns START_PENDING, reboot the device. If rebooting the device doesn't address the issue, upgrade to KB4015217 and try onboarding again.
If the message of the error is: System error 577 or error 1058 has occurred, you need to enable the Microsoft Defender Antivirus ELAM driver, see Ensure that Microsoft Defender Antivirus is not disabled by a policy for instructions.
Hope this helps with your query,
-----------
--If the reply is helpful, please Upvote and Accept as answer--