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