Finding unused app pools with powershell

I’ve been tasked with cleaning up our UAT environment, and needed a way to find unused App Pools. To make things more exciting, we don’t have Microsoft.Web.Administration.ServerManager installed, so the native powershell way wasn’t going to work. This is my solution, by invoking appcmd and string parsing the results.

$command = "c:\windows\system32\inetsrv\appcmd.exe list app"
$apps = Invoke-Expression $command

$command = "c:\windows\system32\inetsrv\appcmd.exe list apppool"
$pools = Invoke-Expression $command
foreach ($pool in $pools)
    $used = $false
    foreach ($app in $apps)
        $apppool = $app
        $apppool = $apppool.Substring($apppool.indexof(":")+1)
        $apppool = $apppool.Replace(")","")
        $apppool = $apppool.trim()
        if ($pool.contains($apppool))
            $used = $true

    echo "$used $pool"

Jenkins on Windows 7

Keith Casey did a talk a talk on Continuous Integration with Jenkins at Sunshine PHP. The first half of the talk was devoted to getting Jenkins installed on our laptops. In a room full of Mackbook Pros, I was one of the few Windows desktops. What follows is my experience with getting it working.

Keith talked about a lot of tools which help to check code quality including

  • Lint
  • Phing
  • CodeSniffer

Install PHP and Pear

  1. Download PHP and install it to c:\php. Add c:\php to your PATH variable.
  2. Download go-pear.phar and save it to c:\php. The information for that is here.
  3. Open an Administrative command prompt
  4. CD to c:\php and run php go-pear.phar. Press enter through all the prompts. Now you have Pear.
  5. Paste the entire giant blob of code into your Administrative command prompt
REM install phpunit
pear channel-update
pear upgrade-all
pear channel-discover
pear channel-discover
pear channel-discover
pear update-channels

REM install phpqatools
pear config-set auto_discover 1
pear install

REM install phing
pear channel-discover
pear install phing/phing-alpha

REM add PSR codesniffer
cd c:\php\pear\php\CodeSniffer\Standards
git clone PSR
phpcs --config-set default_standard PSR

Pear will park .bat files in c:\php for all the modules you installed. Notice that phing is installed as phing-alpha. This is only necessary until 2.7.0 is promoted to stable.

You also need to install Git for Windows.  Use MsyGit and pick “Git from Windows command prompt”.

Lastly, edit your php.ini and enable the extension php_xsl.dll

Install Jenkins

This was pretty straight forward. It’s a Java based project, and there is a Windows installer. Make sure to run the setup.exe, not the MSI.

Once Jenkins is installed, connect to http://localhost:8080/. If the Jenkins dashboard opens, it works!

The web2project example

Keith used one of his own projects, web2project, to demonstrate Jenkins. Getting the toolchain working on windows was a challenge.

  1. Login to the web console
  2. Click Manage Jenkins –> Manage Jenkins
  3. Under Updates, click available updates
  4. Install: Git, Github, PMD, Phing, CPD. A restart of the jenkins service may be necessary
  5. Go back to the dashboard
  6. Click New Job –> Build a freestyle project called web2project
  7. Under source code management, pick git and use the path
  8. Under build pick a custom windows batch command and fill in: cd unit_tests & phing metrics
  9. Click save and build now