I’m trying to create a simple web service using PowerShell that will return a result when called. I want to host this web service on IIS, but I’m running into issues.
Here’s what I’ve done so far:
I created a PowerShell script that outputs some JSON data.
I set up IIS to execute this script by adding a handler for .ps1 files.
I used the CGI module in IIS to handle the PowerShell script.
However, when I try to call the web service, I get the following error:
HTTP Error 502.2 – Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are “”.
I’ve made sure that my script outputs the necessary HTTP headers like Content-Type, but the error still occurs. I’ve also checked the event logs, but I’m not sure what to look for.
Has anyone successfully hosted a PowerShell script as a web service on IIS? If so, could you guide me on how to fix this error or suggest a better approach?
Any help would be greatly appreciated!
4