Setting up and managing device configurations using Intune
If a script is user-based, it must be run as local user. If script is system based, it must be run as a system context in Intune. In system context, one issue you hit is %userprofile%, if your script contains userprofile variables.
You also can add logging in Powershell script and later investigate the log file for errors.