Just as a reminder.
When getting this error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
…just add this to your PowerShell script:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Got another error:
PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Cannot set property. Property setting is supported only on core types in this language mode.
At line:1 char:1
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolTy …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertySetterNotSupportedInConstrainedLanguage
Maybe you use PowerShell Core or PowerShell 6 or 7 ?