Powershell asp to recycle IIS AppPool

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 month ago.

  • Author
    Posts
  • #64696
    Profile photo of Thomas
    Thomas
    Participant

    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.

  • #64780
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

    • #64878
      Profile photo of Thomas
      Thomas
      Participant

      Hi Don,

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

  • #64890
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.