none
Problems setting properties of app pools in PowerShell RRS feed

  • Question

  • Hi all,

    I'm writing a script to deploy web applications to web servers.  In the middle of the script is a code block which should allow the user to change the properties of the application pool as they wish, but I am running into some problems.  The code works fine to change the "name" property, but not for the "autoStart" or "queueLength" properties.  I have not tested all of the properties but I suspect for many of them it will not work.  The relevant code block is below:

    do
    {
        $INPUTNAME = Read-Host "Enter the application pool name"
        Write-Host ""
        do
        {
            $INPUTPROPERTY = Read-Host "Enter the name of the property you wish to configure"
            Write-Host ""
            $INPUTVALUE = Read-Host "Enter the value you wish to set the property '$INPUTPROPERTY' to"
            Write-Host ""
            $INPUTPATH = "IIS:\AppPools\{0}" -f $INPUTNAME
            if (!(Test-Path $INPUTPATH))
            {
                Write-Host "Error: the specified path '$INPUTPATH' does not exist" -ForegroundColor Red
                Write-Host ""
                Break
            }
            Get-Item $INPUTPATH | Set-ItemProperty -Name "$INPUTPROPERTY" -Value "$INPUTVALUE"
            $OUTPUTITEM = Get-Item $INPUTPATH
            if ($OUTPUTITEM.$INPUTPROPERTY -eq $INPUTVALUE)
            {
                Write-Host "Application pool '$INPUTNAME' property '$INPUTPROPERTY' successfully changed to '$INPUTVALUE'" -ForegroundColor Green
                Write-Host ""
            }
            else
            {
                Write-Host "Error: could not change application pool '$INPUTNAME' property '$INPUTPROPERTY' to '$INPUTVALUE'" -ForegroundColor Red
                Write-Host ""
            }
            $CONTINUEONE = Read-Host "Would you like to configure another property of this application pool? <Y/N>"
            Write-Host ""
        }
        until ($CONTINUEONE -eq "N")
        $CONTINUETWO = Read-Host "Would you like to configure another application pool? <Y/N>"
        Write-Host ""
    }
    until ($CONTINUETWO -eq "N")

    Weirdly, for the "autoStart" property, the script returns that it has been successfully changed but checking it in the GUI or another PowerShell instance shows that this is not the case.  Can anyone see what I'm doing wrong?

    Thanks in advance!

    Note: yes, I write very verbose.  My scripts are designed with readability in mind, and I'm quite new

    Thursday, July 17, 2014 11:58 AM

Answers

All replies

  • Please post IIS specific questions in the IIS forum.  http://forums.iis.net


    ¯\_(ツ)_/¯

    Thursday, July 17, 2014 12:09 PM
  • Well, since this is not to do directly with IIS, but to do with the PowerShell script which I'm writing, I don't think it's out of place here
    Thursday, July 17, 2014 1:07 PM
  • Well, since this is not to do directly with IIS, but to do with the PowerShell script which I'm writing, I don't think it's out of place here

    No - the problem is that IIS has the files open. Only IIS can solve your issue.  You need to understand how to manage an IIS instance and app.  The link posted will put you in contact with people who will tell you how to correctly manage IIS with PowerShell or any other tool.

    '


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, July 17, 2014 1:28 PM
    • Proposed as answer by jrv Friday, July 18, 2014 12:35 PM
    Thursday, July 17, 2014 1:27 PM
  • Ok, thanks for your help. I have posted a question on the IIS forums so hopefully this will be resolved soon

    Thursday, July 17, 2014 1:48 PM
  • So the good folks at the IIS forums gave me this answer, which works a treat:

    Pengzhen Song - MSFT

    Hi,

    I think it should ok. Please try testing the code below:

    $pool = Get-Item 'IIS:\AppPools\DefaultAppPool'
    $pool.autoStart = 'true'
    $pool | Set-Item

    For more information, you can refer to the blog:

    http://msdn.microsoft.com/en-us/library/ee677285(v=azure.10).aspx

    Friday, July 18, 2014 9:59 AM