When executing a PowerShell script in the Shell or in an IDE, the script executes as expected, but when running it as a Windows Scheduled Task, the script fails to connect to Active Roles. This failure may present in a number of different ways, depending on how the connection is implemented.
Connect-QADService fails to connect with the error:
The remote endpoint does not exist or could not be located.
When configuring the Scheduled Task, on the General tab, there is a checkbox labeled Do not store password. The task will only have access to local resources. This checkbox must be cleared.
If, when this checkbox is cleared, the Scheduled Tasks fails to execute with the following error:
A specified logon session does not exist. It may have already been terminated.
This indicates that the Local Security Policy setting Network access: Do not allow storage of passwords and credentials for network authentication is enabled. This must be disabled in order for a scheduled task to store and pass a credential. If this option is enabled and enforced via Window Group Policy, then this Group Policy needs to be changed or the Scheduled Task needs to be configured on a host where this Group Policy is not enforced.