Thank you for posting in Microsoft Q&A forum.
We may check the result of the script on the device by going to Windows Logs > Application and looking for an event from WDATPOnboarding event source. If the script fails and the event is an error, we can check the event ID in the following table to help you troubleshoot the issue.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Add comment".