I'm running a PowerShell script that posts data to an internal webserver over HTTPS. The SSL certificate is not valid. I'm using
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
to accept the certificate and it works when the script is ran from the command line but I get the error
You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
when ran as a scheduled task. The exact command is
Invoke-WebRequest -Uri 'https://host/login.cgi' -Method POST -Body 'username&password' -UseBasicParsing
In the end, I just reverted to more basic .NET functionality: