If your version of Invoke-SqlCmd
does not allow usage of this flag TrustServerCertificate
(for any reason, also mentioned in other answers), try to exclude this flag from execution - that was enough in my case, because in this case a certificate was not required. (Not a best advice, but works).