How can I use TLS 1.3 with Invoke-RestMethod?


When I call

Invoke-RestMethod -Method POST -Uri $url -Body $Body -Headers $Header …

I get:

Authentication failed because the remote party sent a TLS alert: 'ProtocolVersion'.

Server is Tomcat 9 with just TLS 1.3 enabled while Powershell uses TLS 1.2 - I've checked with Wireshark:

TLSv1.2 Record Layer: Handshake Protocol: Client Hello
    Content Type: Handshake (22)
    Version: TLS 1.2 (0x0303)
    Length: 167
    Handshake Protocol: Client Hello

I then set

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13

But I get the same error: Powershell still sends a TLS 1.2 Client Hello

How can I use TLS 1.3 from my Powershell scripts?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,408 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karl Wester-Ebbinghaus 36 Reputation points MVP

    The command of might not work ::TLS13 at the moment, depending the OS version.
    Just tried it on Windows 11 with PowerShell 5.1 and 7.x and it was accepted.

    According to some other documentation it is still a separate way to declare TLS 1.2, which I thought would be TLS 1.3 but it still 1.2, just looked so unusual to me, when I saw it in the script. The reason is they did not use the Displayname but the value, see ".net view".

    [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072;
    source: Azure Arc Onboarding Script

    Copilot says PS does not support TLS 1.3. But it seems it depends on the .net, PowerShell 5.1+ and OS version used.

    OS view (SCHANNEL etc):

    .net view (including [Net.ServicePointManager] class)

    further references:

    Hope this helps you.

    0 comments No comments