Powershell asp to recycle IIS AppPool

Hi guys

Been looking into a little ps1x script to run on a IIS webserver with Powershell ASP.
The scripts function will be to recycle an AppPool, but running into some issues. This is a dev server with a lot of AppPools running and they sometime crash the webapplication running, so setting up this to fast recycle the AppPool and move on.

The code snippet i use for a test runs just fine from Powershell ISE, but as soon as i move it over to the PS1x file in the inetpub folder and launch it via a browser, nothings happens. It just writes “ID” at the top of the page.

I have the AppPool the site is running as set up as the local administrator account, but also tried with my own (that is in the admin group).

https://paste.ofcode.org/kqKgYfb7ywGWFD9x3un26t

If i run this code

https://paste.ofcode.org/34qDvLuTEKatqMtxZEP9JV8

Then i can see the IIS drive is there (and not if i don’t load WebAdministration module in the top of the script.

Anyone have an idea of what is wrong and how to solve it.

EDIT: had to use PasteOfCode site, since the editor here doesn’t work with the code i pasted in.

I’m not sure what you mean by “launch it via a browser.” You’re launching a .ps1 script as a Web page?

Hi Don,

Yes launching them as a .ps1x script page via Powershell ASP

So, unfortunately I’ve no idea what kind of runtime environment that sets up. My guess is that it’s not setting things up the same as the console. Not every hosting application sets up the exact same environment - for example, it may not be using PSModulePath to do module auto-discovery. You’d need to contact whoever made PowerShell ASP and ask.