Download powershell (.ps1) file via ASP.NET

Question:

I’ve got a .ps1 file that I would like to link readers to. Unfortunately, navigating to that URL only results in a 404. If memory serves, this is being “blocked” just like .config files, but there’s a way to change that configuration in web.config … but I can’t seem to find the correct thing via search.

TL;DR, how can I expose a .ps1 powershell script so that it’s accessible (though not executable, obviously) via HTTP.

Answer:

I believe you need to add a MIME type for .ps1. In your IIS Manager, select the server node on the tree, and click “MIME Types”. Then click “Add…” on the right panel. For extension, set it to .ps1, and set the MIME type to text/plain.

Now IIS should serve .ps1 files.

You could use a MIME Type of application/octet-stream instead of text/plain. Using the former will cause most browsers to download it rather than try to display it.

You can do this for a specific web application or virtual directory, too. If you are doing this through web.config, it would look something like this:

Source:

Download powershell (.ps1) file via ASP.NET by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply