Udostępnij za pośrednictwem


Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send. while using PowerShell

 

If you have gotten the "Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send." error while using PowerShell then add the line below to your script.

    ​[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

PowerShell calls uses TLS 1.0 for web requests by default. However, Exchange is expecting a higher level of TLS, so you need to tell PowerShell to use 1.2 instead of the default of TLS 1.0.

Below are links for additional information.

An Update on Office 365 Requiring TLS 1.2
https://blogs.technet.microsoft.com/exchange/2018/02/09/an-update-on-office-365-requiring-tls-1-2/

    Preparing to use TLS 1.2 in Office 365
    https://support.microsoft.com/en-us/help/4057306/preparing-for-tls-1-2-in-office-365