Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel

Hi, I have a simple script that runs a Post API

$MyUrl = "https://..."
Invoke-RestMethod -Uri MyUrl -Method POST

But i get the error in the title. I tried it on 3 different PC’s, with Windows 7, Windows 10 and Windows 11 respectively.

On Windows 10 and 11 it worked after installing the right certificate, on Windows 7 it still doesn’t work

In case it matters here is the PS Version on 2 of the PC’s

Thank you in advance

Check the TLS version, you probably need to force it to use TLS 1.2.

You can check the available versions with:

[System.Net.ServicePointManager]::SecurityProtocol

To enable TLS1.2 for the session you can use this command:

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

This worked, thank you so much