@X-Box-11-2021, Thanks for posting in Q&A.
From your description, I know you got the error of PowerShell execution has exceeded defined timeout.
Based on my research, the error means a script takes longer to execute than the maximum time allowed by Intune.
Here are some steps you can take to troubleshoot and resolve this issue:
1.Review the script to identify any inefficiencies or unnecessary operations that can be optimized to reduce execution time. Break down the script into smaller parts and test each part individually to identify the slowest sections.
Here are some related issues you can refer to.
https://www.reddit.com/r/Intune/comments/impu1m/powershell_script_successfully_runs_however/
https://www.reddit.com/r/Intune/comments/icinc3/intune_marks_ps_script_as_failed_even_thought_it/
Non-official, just for reference.
2.It is well known that script execution is very slow in Intune and if you want to make it faster, you would need to create win32 app of the script.
https://tech.tristantyson.com/DeployPowershellAsAWin32App
Non-official, just for reference.
Hope above information can give you some ideas.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.