Forum Discussion
Exchange Online Powershell not connecting in scheduled Task script
- Jan 13, 2025
It took me long time, but after creating a seperate scheduled script (only for testing Exchange Online connection), I finally found the issue.
The new script worked fine, so it had to be something about my old script.As it turned out, we had a Webserver API Call executing before the ExO connect in our script and I assume the connection never closed correctly. After I removed / moved this API call, the script is working fine.
Maybe it was blocking the same socket, which the script uses to connect to Exchange?Probably not really useful for you, but I hope it helps anyway.
ThomasStensitzki-MVP thank you for your help.
We are running this on Windows Server 2016 Datacenter.
TLS 1.2 client is enabled.
Here you can see all the tls settings:
Path Name Value
---- ---- -----
HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 SystemDefaultTlsVersions 1
HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 SchUseStrongCrypto 1
HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319 SystemDefaultTlsVersions 1
HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319 SchUseStrongCrypto 1
HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727 SystemDefaultTlsVersions 1
HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727 SchUseStrongCrypto 1
HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v2.0.50727 SystemDefaultTlsVersions 1
HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v2.0.50727 SchUseStrongCrypto 1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server Enabled Not Found
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server DisabledByDefault Not Found
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client Enabled Not Found
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client DisabledByDefault Not Found
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server Enabled 1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server DisabledByDefault 0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client Enabled 1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client DisabledByDefault 0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server Enabled 0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server DisabledByDefault 1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client Enabled 0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client DisabledByDefault 1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server Enabled 0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server DisabledByDefault 1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client Enabled 0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client DisabledByDefault 1
And can you check if the use of Remote PowerShell is enabled for the account having the issues?
Get-User -Identity <UserIdentity> | Format-List RemotePowerShellEnabled
-Thomas
- Patrick0411Aug 12, 2024Copper ContributorI don't really see how this is relevant when using certificate based authentication.
The User running the script is not synced tho Azure at all. But he still can connect to exchange online when running the script manually. So I am pretty sure, this is not a requirement.- JoepelusDec 20, 2024Copper Contributor
Did you figure this out, im running into the same issue, script works fine manually (Certificate based authentication) but fails as a scheduled task.
- Patrick0411Jan 13, 2025Copper Contributor
It took me long time, but after creating a seperate scheduled script (only for testing Exchange Online connection), I finally found the issue.
The new script worked fine, so it had to be something about my old script.As it turned out, we had a Webserver API Call executing before the ExO connect in our script and I assume the connection never closed correctly. After I removed / moved this API call, the script is working fine.
Maybe it was blocking the same socket, which the script uses to connect to Exchange?Probably not really useful for you, but I hope it helps anyway.