Set the disconnected session timeout to never log you off.
configure-remote-desktop-connection-disconnected-session-timeout
Another option is to use the Task Scheduler to run your script. That will likely require modifications since it would be running in an unattended session with no user interface. It all depends on what the script does and how you use it.