CanUpgrade [Microsoft.SharePoint.Administration.SPIisWebSite] failed.

How do I always seem to be the guy finding this stuff is beyond me, but I'm always excited when I figure this stuff out…ok, was getting this error after trying to run the PSConfig after an upgrade to SP1 and December 2011 CU.

[OWSTIMER] [SPUpgradeSession] [INFO] [1/8/2012 1:48:44 PM]: SPWebApplication Name=SharePoint – xxx
[OWSTIMER] [SPUpgradeSession] [ERROR] [1/8/2012 1:48:44 PM]: CanUpgrade [Microsoft.SharePoint.Administration.SPIisWebSite] failed.
[OWSTIMER] [SPUpgradeSession] [INFO] [1/8/2012 1:48:44 PM]: SPWebApplication Name=SharePoint – xxx
[OWSTIMER] [SPUpgradeSession] [ERROR] [1/8/2012 1:48:44 PM]: Exception: The system cannot find the path specified.
[OWSTIMER] [SPUpgradeSession] [INFO] [1/8/2012 1:48:44 PM]: SPWebApplication Name=SharePoint – xxx
[OWSTIMER] [SPUpgradeSession] [ERROR] [1/8/2012 1:48:44 PM]:    at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at Microsoft.SharePoint.Administration.SPIisVirtualDirectory.get_Path()
   at Microsoft.SharePoint.Administration.SPProvisioningAssistant.GetBuildVersionOnIisWebSite(Int32 iisInstanceId)
   at Microsoft.SharePoint.Upgrade.SPSequence.get_CanUpgrade()
   at Microsoft.SharePoint.Upgrade.SPUpgradeSession.CanUpgrade(Object o)

So what is causing this?  Using the handy reflector tool I went into the upgrade code and found the sequence that upgrades SPWebApplication objects.  This creates a list of all children objects that must be upgraded and then upgrades those objects one by one.  One of the children objects is the created or extended IIS web sites.  In order to check if these "CanUpgrade", it must look at the file in the IIS virtual directory "_vti_pvtuildversion.cnf".  If it can't find this file (the virtual path is deleted or missing), then the upgrade will stop for that web application and your upgrade is stuck in a weird state with this crappy error "Product / patch installation or server upgrade required"!

How do you fix?  You can try to add the directory back, but how do you know what the directory is that you need to add?  Funny thing, you can't find it unless you open up the SharePoint_Config database.  I will spare you the details and jump to the "supported" way of fixing this.  In Central administration you won't see the offending missing zone to delete it, therefore you must resort to powershell:

$webapp = get-spwebapplication "http://yourfailedurl"

foreach($setting in $webapp.iissettings.values)
{
$setting.path
}

foreach($zone in $webapp.iissettings.keys)
{
$z = $zone
}

$webapp.IisSettings.Remove("missingzone")
$webapp.update()

Rerun your PSconfig command, viola, you are back in business!!!

Enjoy!
Chris