'Invoke-Webrequest' works fine on prompt but fails when executed through

214 views Asked by At

I am reading latest code from github to update the procs. It works well when I execute from powershell. But it fails when I do from SQL Server Agent Job. This is the format of my code

cd "C:\Folder\" [Net.ServicePointManager]::SecurityProtocol ='Ssl3, Tls, tls12' Invoke-WebRequest https://raw.githubusercontent.com/repository/folder/file.sql -Headers @{"Authorization"="token xxxxxxxxxxxxxxx";"Accept"= "application/vnd.github.v3.raw"} -OutFile ./file.sql

ExecutionPolicy is set Unrestricted I am using SQL Server 2012 sp4 (KB4018073) on Windows 2012 R2.

It was working few weeks back and I suspect that it started failing only after Wndows Security updates. These are the updates installed recently: Security Update for Windows (KB5023790) Security Update for Windows (KB5025288) Security Update for Windows (KB5023764) Security Update for Windows (KB5026415) Security Update for Windows (KB5026409) Security Update for Windows (KB5026366) Update for Windows (KB3191564) Update for Windows (KB3031044) Update for Windows (KB5023822)

Any clues? guidelines?

I even tried executing it using cmdExec type (calling powershell.exe). It is not working. I am not getting any specifc error. I tried with Sql using xp_cmdshell and it is also failing.

But it is working when I executed from powershell or command prompt .

0

There are 0 answers