Friday, May 14, 2010

Collecting IIS Website Config via SCCM Hardware Inventory

Recently I was tasked with collecting basic IIS Website configuration via SCCM Hardware Inventory. I thought it would be as simple as adding the following to the SMS_def.mof:

[ SMS_Report (TRUE),
SMS_Group_Name ("IIS_Website"),
SMS_Namespace (False),
Namespace ("\\\\\\\\.\\\\root\\\\MicrosoftIISv2"),
SMS_Class_ID ("MICROSOFTIIS_Website1.0") ]

class IIsWebServerSetting : SMS_Class_Template
{
[SMS_Report (TRUE), key]
STRING Name;
[SMS_Report (TRUE) ]
STRING AppFriendlyName;
[SMS_Report (TRUE) ]
BOOLEAN AuthAnonymous;
[SMS_Report (TRUE) ]
BOOLEAN AuthBasic;
[SMS_Report (TRUE) ]
STRING DefaultDoc;
[SMS_Report (TRUE) ]
STRING DefaultLogonDomain;
[SMS_Report (TRUE) ]
STRING LogFileDirectory;
[SMS_Report (TRUE) ]
STRING ServerComment;
};


However, upon a hardware inventory, only the last collected Website would stick. For some reason, all but the last one was being overwritten in the database and moved to the _Hist table. Another thing that was puzzling, was that I was able to collect the IISWebVirtualDirSetting class, which basically has the same data and structure as the IISWebServerSetting class.

So, after a week of troubleshooting along with waiting for someone to reply to my post on technet (http://social.technet.microsoft.com/Forums/en/configmgrinventory/thread/82c3e55f-50de-449d-84fe-be6c957265d2), I decided that a custom solution was in order. Perhaps, at some point, someone will inquire w/ Microsoft as to to what makes this class different from the IISWebVirtualDirSetting class. Until then, I've provided my solution below.

First, I created a custom mof addition (below) and placed it in the configuration.mof file. This creates the IIS_Website class in the cimv2/sms namespace. I've taken out our organizations Class prefix. A prefix is probably a good idea so that you can later discern between standard and custom config.

Configuration.mof Addition

#pragma namespace ("\\\\.\\root\\cimv2\\SMS")
class IIS_Website

{
[key]
STRING Name;
STRING ServerComment;
STRING AppPoolId;
STRING DefaultDoc;
STRING DefaultLogonDomain;
STRING LogFileDirectory;
};

Next, I populate the class by advertising out the below Powershell script to our servers on a recurring basis.

iis_website.ps1

// variable that holds all instances in the custom IIS_Website class
$smsWebs = Get-WmiObject -namespace "root/cimv2/sms" -class "IIS_Website"
// cleanup the custom IIS_Website class by removing all of the instances

ForEach ($smsWeb in $smsWebs) {
if ($smsWeb) {
$smsWeb Remove-WmiObject }
}
// variable to hold all instances in the IISWebServerSetting class

$Webs = Get-WmiObject -namespace "root/MicrosoftIISv2" -class "IIsWebServerSetting"
// test that there are instances of the IISWebServerSetting class

// if there are, iterate through the instances and write to the custom IIS_Website Class
if ($Webs) {
ForEach ($Web in $Webs) {
$name = $Web.Name
$serverComment = $Web.serverComment
$appPoolId = $Web.AppPoolId
$defaultDoc = $Web.DefaultDoc
$defaultLogonDomain = $Web.DefaultLogonDomain
$logFileDirectory = $Web.LogFileDirectory
Set-WmiInstance -namespace "root/cimv2/sms" -class "IIS_Website" -argument @{
Name="$name";
ServerComment="$serverComment";
AppPoolId="$appPoolId";
DefaultDoc="$defaultDoc";
DefaultLogonDomain="$defaultLogonDomain";
LogFileDirectory="$logFileDirectory";
}
}
}


Lastly, I've placed the following in the sms_def.mof in order to collect the data now stored in the IIS_Website class.

SMS_def.mof Addition

[ SMS_Report (TRUE),
SMS_Group_Name ("IIS_Website"),
SMS_Namespace (TRUE),
SMS_Class_ID
("MicrosoftIIS_Website1.0") ]


class
IIS_Website : SMS_Class_Template
{

[SMS_Report (TRUE), key]
STRING Name;
[SMS_Report (TRUE) ]
STRING AppPoolId;
[SMS_Report (TRUE) ]
STRING DefaultDoc;
[SMS_Report (TRUE) ]
STRING DefaultLogonDomain;
[SMS_Report (TRUE) ]
STRING LogFileDirectory;
[SMS_Report (TRUE) ]
STRING ServerComment;
};


This solution was carefully tested prior to implimentation in production. I suggest the same approach to anyone who may want to use this to gather IIS data. Anyway, my next step is to create a forward and reverse lookup reporting the server(s) where a given website lives and what website(s) live on any given server.

Enjoy!

1 comment:

  1. Hi,

    I am looking for the same info. do you have report created which will give this info.

    ReplyDelete