Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Problems setting properties of app pools in PowerShell

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>