I have a Powershell script that invokes a REST API call to get a cert from a server. The script runs just fine if I trigger it manually from the machine. However, when I setup the script to run at Start using the steps here: http://blogs.technet.com/b/heyscriptingguy/archive/2014/05/14/use-powershell-to-create-job-that-runs-at-startup.aspx, then the script does not run at all.
I setup a .bat scripts to under the same StartUp folder (as mentioned in the article above) and they run just fine.
Any pointers or suggestions to help resolve or debug the issue will be helpful.
EDIT: Here is the script
# Fake the Certificate Validation as we are using a HTTPS request without a real cert
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$uri = "https://10.X.Y.Z/webapp-rest/login?&user=user1&pw=super_secure"
$res = Invoke-WebRequest -Uri $uri -Method Post
$headers = @{}
$headers.Add('Authorization', $res.Headers.Authorization)
$uri1 = "https://10.X.Y.Z/webapp-rest/certificate"
$sm = Invoke-RestMethod -Uri $uri1 -Headers $headers -ContentType application/x-x509-ca-cert -OutFile "cert.pem"
Move-Item C:\cert.pem C:\Users\Administrator\Downloads -Force