November 2010 (1)
August 2010 (1)
July 2010 (1)
June 2010 (3)
July 2009 (3)
June 2009 (1)
May 2009 (1)
February 2009 (1)
January 2009 (1)
November 2008 (3)
October 2008 (4)
September 2008 (9)
August 2008 (6)
July 2008 (3)
June 2008 (3)
January 2008 (1)
November 2007 (2)
October 2007 (6)
September 2007 (5)
August 2007 (22)
July 2007 (6)
June 2007 (1)
May 2007 (3)
April 2007 (27)
March 2007 (8)
February 2007 (6)
September 2006 (2)
August 2006 (4)
July 2006 (9)
June 2006 (17)
May 2006 (20)
April 2006 (12)
March 2006 (9)
February 2006 (4)
January 2006 (3)
December 2005 (2)
November 2005 (4)
October 2005 (5)
September 2005 (37)
August 2005 (83)
July 2005 (6)

Active Directory / LDAP (0)
ASP.Net (19)
Blackberry Development (4)
c# (34)
c++ (3)
Code Camp (1)
Excel (1)
Exchange (3)
Front Page 2003 (6)
FTP User Editor (4)
HTML / CSS / DHTML (8)
IIS (146)
IIS - Log Parser (7)
IIS / FTP (12)
IIS / Tools / Administration (42)
IIS / Tools / Authentication (6)
IIS / Tools / Compression (8)
IIS / Tools / Crash & Hang (12)
IIS / Tools / ISAPI Filters (17)
IIS / Tools / Log Files (17)
IIS / Tools / Scripts (28)
IIS / Tools / Security (9)
IIS / Tools / SSL (6)
IIS 7 (3)
Internet Information Server (1)
Me (Chris Crowe) (6)
MIME Types (1)
Misc (72)
Oulook Express (2)
Silverlight (1)
SQL Server (27)
SQL Server CTE (1)
Vista (15)
Vista Gadgets (8)
Visual Studio (11)
Voice over BroadBand (1)
Windows (33)
Windows Powershell (3)
Windows Sharepoint Services (0)
Windows Sharepoint Services (15)
Windows Vista (14)
Wine Cellar (1)
WMI (8)
WMI (8) blog.crowe.co.nz.Models.Category

WMI

Some examples of scripting of IIS using ADSI, WMI from VB and C# including the new Microsoft.Web.Administration namespace

Below are some simple examples of how to talk to IIS via ADSI, WMI and the new IIS 7 only .NET Managed Provider.

The IIS ADSI Provider

The IIS ADSI provider exposes COM Automation objects that you can use within command-line scripts, ASP pages, or custom applications to change IIS configuration values stored in the IIS metabase. IIS ADSI objects can be accessed and manipulated by any language that supports automation, such as Microsoft® Visual Basic® Scripting Edition (VBScript), Microsoft JScript®, Perl, Microsoft Active Server Pages (ASP), Visual Basic, Java, or Microsoft C++.

The IIS WMI Provider

Windows Management Instrumentation (WMI) is a technology that allows administrators to programmatically manage and configure the Windows operating system and Windows applications. Beginning with IIS 6.0, IIS includes a WMI provider that exposes programming interfaces that can be used to query and configure the IIS metabase.

The Microsoft.Web.Administration namespace in IIS 7

 This is a new .NET managed namespace that will allow you to talk to IIS 7 and configure all aspects of the server. This API is designed to be simple to code against in an “intellisense-driven” sort of way. At the root level a class called ServerManager exposes all the functionality you will need. At this time it appears that this will not be able to be used from Windows XP but by the time Vista & Windows Server are released this may have been ported to run on a Windows XP client.
 

For more details on these technologies see the following resources:


C# -Using System.DirectoryServices and ADSI

using System;
using System.Collections.Generic;
using System.Text;
// Must be specified and a reference added to System.DirectoryServices
using System.DirectoryServices;

namespace Console_EnumSites_ADSI_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/W3SVC");
            foreach (DirectoryEntry site in entry.Children)
            {
                if (site.SchemaClassName == "IIsWebServer")
                {
                    string ServerComment = site.Properties["ServerComment"].Value.ToString();
                    Console.WriteLine(ServerComment + " (" + site.Name + ")");
                }
            }
        }
    }
}

VB -Using ADSI

on error resume next

dim websrv, site
dim webinfo

set websrv = getobject("IIS://Localhost/W3SVC")
if (err <> 0) then
else
    err.Clear
    for each site in websrv
        if (site.classname = "IIsWebServer") then
            WScript.echo Site.ServerComment & " (" & Site.Name & ")"
        end if
    next
end if

C# -Using System.Managment and WMI

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace Console_EnumSites_WMI_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementScope oms = new ManagementScope(@"\\.\root\MicrosoftIISv2");
            oms.Connect();

            ObjectQuery oQuery = new ObjectQuery("select * from IISWebServerSetting");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oms, oQuery);
            foreach (ManagementObject oreturn in oSearcher.Get())
            {
                Console.WriteLine(oreturn["ServerComment"]+" ("+oreturn["Name"]+")");
            }
            Console.Read();
        }
    }
}

C# -Using Microsoft.Web.Administration ( II7 Only )

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;

namespace Console_EnumSites
{
    class Program
    {
        static void Main(string[] args)
        {
            ServerManager iisManager = new ServerManager();

            Console.WriteLine("Display IIS Sites in IIS 7");
            Console.WriteLine("".PadLeft(40,'-'));
            foreach(Site site in iisManager.Sites)
            {
                Console.WriteLine("{0} {1}", site.Id.ToString().PadRight(12), site.Name);                
            }
            Console.Read();
        }
    }
}

Microsoft Scripting Resources

I came across a number of cool scripting utilities today that may help others; these are:

  • Do-It-Yourself Script Center Kit
  • Scriptomatic 2.0
  • TechNet Script Center Sample Scripts
  • WMI Code Creator v1.0
  • HTA Helpomatic
  • TechNet Script Center Sample Scripts
  • Technet Script Center
  • ADSI Scriptomatic
  • Tweakomatic

Do-It-Yourself Script Center Kit

The Do-It-Yourself Script Center Kit includes all the materials you need to create your own version of the TechNet Script Center, either as stand-alone Web pages, stand-alone .vbs files, or as a .chm Help file. Included in the Kit are a database ( Microsoft Access ) of all the scripts found in the TechNet Script Center Script Repository as of January 2005, as well helper scripts for creating Web pages, .vbs files, and .chm files.

The Kit also includes instructions for using these helper scripts.

For more details see:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=D187C9D7-FFA8-49CD-BB33-363DB8FA481E&sGuid=8c9e492e-9f9b-4f33-8bad-26c69ee9a42b&hash=P8DMHJ

Scriptomatic 2.0

A completely new version of the famous Scriptomatic, the utility that writes WMI scripts for you. (And, in the process, teaches you the fundamental concepts behind writing WMI scripts for yourself.) U

nlike its predecessor, Scriptomatic 2.0 isn’t limited to writing just VBScript scripts; instead, Scriptomatic 2.0 can write scripts in Perl, Python, or JScript as well.

In addition, Scriptomatic 2.0 gives you a host of new output formats to use when running scripts, including saving data as plain-text, as a stand-alone Web page, or even as XML.

Scriptomatic 2.0 handles arrays, it converts dates to a more readable format, and it works with all the WMI classes on your computer; on top of all that, it also writes scripts that can be run against multiple machines.

For more details see:
http://www.microsoft.com/downloads/details.aspx?familyid=09DFC342-648B-4119-B7EB-783B0F7D1178&displaylang=en

Incase you want the old 2002 version :
http://www.microsoft.com/downloads/details.aspx?familyid=9EF05CBD-C1C5-41E7-9DA8-212C414A7AB0&displaylang=en

TechNet Script Center Sample Scripts

Sample scripts found in the TechNet Script Center. The sample scripts are not supported under any Microsoft standard support program or service. You can, however, report issues and bugs by sending e-mail to scripter@microsoft.com.
 

HTA Helpomatic

The HTA Helpomatic is a utility that helps script writers create HTML Applications (HTAs). HTAs enable you to provide a graphical user interface for your scripts, an interface that can include anything from list boxes to radio buttons to checkboxes. The HTA Helpomatic includes sample VBScript code and sample HTML code showing you how to do things like add a button to an HTA. Equally important, the Helpomatic also shows you how you can run a script any time that button is clicked. As an added bonus, the Helpomatic enables you to modify the scripts and HTML code and test those modifications in the utility itself.

For more details see:
http://www.microsoft.com/downloads/details.aspx?familyid=231D8143-F21B-4707-B583-AE7B9152E6D9&displaylang=en

WMI Code Creator v1.0
The WMI Code Creator tool generates code that uses WMI to obtain management information or perform management tasks. You can use the tool to learn how to manage computers using WMI scripting and WMI .NET. The tool generates code that runs on the local computer, a remote computer, or a group of remote computers based on your selection from the Target Computer menu on the tool. You can also execute the generated code directly from the tool.

The tool is meant to help IT Professionals quickly create management scripts and to help developers learn WMI scripting and WMI .NET. The tool helps take the complexity out of writing code that uses WMI and helps developers and IT Professionals understand how powerful and useful WMI can be for managing computers.

Using the tool, you can query for management information such as the name and version of an operating system, how much free disk space is on a hard drive, or the state of a service. You can also use the tool to execute a method from a WMI class to perform a management task. For example, you can create code that executes the Create method of the Win32_Process class to create a new process such as Notepad or another executable. The tool also allows you to generate code to receive event notifications using WMI. For example, you can select to receive an event every time a process is started or stopped, or when a computer shuts down.

The tool also allows you to browse through the available WMI namespaces and classes on the local computer to find their descriptions, properties, methods, and qualifiers.

The code that creates the tool is also included in the download. The tool was created using WMI .NET, and the code for the tool can help developers understand how WMI .NET is used to create applications and manage information. Be sure to read the end-user license agreement that is included in the download.
 
For more details see:
 
Technet Script Center
The TechNet script center is a repositaty specially tailed for scripting, there are columns and verything you need to learn how to write scripts for Windows is right there!
 
Find articles, documentation, webcasts, and even hands-on labs for all levels, right at your fingertips.
 
 
ADSI Scripomatic
The ADSI Scriptomatic is designed to help you write ADSI scripts; that is, scripts that can be used to manage Active Directory or IIS.
 
The ADSI Scriptomatic also teaches you an important point about ADSI scripting: like WMI, there are consistent patterns to ADSI scripts.
 
For example, the ADSI Scriptomatic will help you write a script to delete a user account. It will also help you write scripts for deleting groups and organizational units.
 
And if you take a close look at the scripts for deleting different objects, you’ll see something very interesting: theyre practical identical!
 
 
Tweakomatic

Tweakomatic is a nifty new utility that writes scripts that enable you to retrieve and/or configure Windows and Internet Explorer settings. So what, you might say. Well, think about it. Because these are Windows Management Instrumentation (WMI) scripts, they can be used to configure settings on remote computers. Need to change something on a remote computer? Then haul out Tweakomatic. And think about this: because Tweakomatic writes scripts, you could do something like run these scripts as logon or logoff scripts. In other words, you could quickly, easily, and automatically configure settings on any or all the computers in your organization. Tweakomatic is undoubtedly the single best thing Microsoft has released since Windows itself

For more details see:
http://www.microsoft.com/technet/scriptcenter/tools/twkmatic.mspx


Exchange - Using WMI to list all mailboxes and their sizes from c#

First off this is my 100th post to my blog!

This is a sample of how to talk to MS Exchange to enumerate all of the mailboxes and display them with the total message count and total message size.

It also shows examples of:

  • Creating your own table
  • Using a DataView to sort the table
  • Writing to XML from a dataset
  • Padding Strings
  • Using the System.Management namespace
using System;

namespace Sample1
{
    /// 
    /// Summary description for Class1.
    /// 

    class Class1
    {
        /// 
        /// The main entry point for the application.
        /// 

        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_wmiref_cl_exchange_mailbox.asp

                System.Console.WriteLine("Enumerate mailbox sizes in MS Exchange Server - Chris Crowe");
                System.Console.WriteLine();

                // Create a DataSet (only needed if you want to save to XML )
                System.Data.DataSet ds = new System.Data.DataSet();
                // Create a DataTable to hold our results
                System.Data.DataTable dt = new System.Data.DataTable("Mailboxes");            
                // Add the table to the dataset
                ds.Tables.Add(dt);

                // Create columns for our data
                dt.Columns.Add(new System.Data.DataColumn("Mailbox"typeof(String)));
                dt.Columns.Add(new System.Data.DataColumn("Messages"typeof(Int32)));            
                dt.Columns.Add(new System.Data.DataColumn("Size"typeof(Int32)));            

                // 
                System.Management.ConnectionOptions objconn = new System.Management.ConnectionOptions();
                objconn.Impersonation = System.Management.ImpersonationLevel.Impersonate;
                // Gets or sets a value indicating whether user privileges need to be enabled for the 
                // connection operation. This property should only be used when the operation performed 
                // requires a certain user privilege to be enabled (for example, a machine reboot).
                objconn.EnablePrivileges = true;

                // Exchange Server Name
                string cServername = "*"// YOUR EXCHANGE SERVER NAME

                // Create a management scrope into the Exchange WMI namespace
                System.Management.ManagementScope exmangescope = 
                    new System.Management.ManagementScope(@"\\" + cServername + @"\root\MicrosoftExchangeV2",objconn);
            
                // Create a query to get the data from the Exchange WMI
                System.Management.ObjectQuery objquery = 
                    new System.Management.ObjectQuery("SELECT * FROM Exchange_Mailbox");

                // Retrieves a collection of management objects based on the query.
                System.Management.ManagementObjectSearcher objsearch = 
                    new System.Management.ManagementObjectSearcher(exmangescope,objquery);

                // Invokes the WMI query and returns the resulting collection.
                System.Management.ManagementObjectCollection queryCollection1 = objsearch.Get(); 

                // Loop through each item in the collection
                foreach( System.Management.ManagementObject instmailbox in queryCollection1 ) 
                {
                    // Add a row of data to our table
                    dt.Rows.Add(new object[] { 
                                                 instmailbox["MailboxDisplayName"],    
                                                 instmailbox["TotalItems"], 
                                                 instmailbox["size"] } );
                } 

                // Used to calculate the size of all of the mailboxes and the message count
                int TotalMessages=0;
                Int64 TotalSize=0;

                // Create a DataView to sort the data by Mailbox Size
                System.Data.DataView dv = new System.Data.DataView(dt);
                dv.Sort = "Size desc, Mailbox";

                // Write a heading
                System.Console.WriteLine(string.Format("{0} {1} {2} "
                    "Mailbox".PadRight(55), 
                    "Messages".PadLeft(8), 
                    "Size".PadLeft(13)));
            
                // Write a line of dashes
                System.Console.WriteLine("".PadRight(78'-'));

                // Get an enumerator to enumate the DataView to get the rows from the table (sorted)
                System.Collections.IEnumerator enumerator = dv.GetEnumerator();            
            
                // Loop through each item in the table
                while(enumerator.MoveNext())
                {
                    // Get a row 
                    System.Data.DataRowView row = enumerator.Current as System.Data.DataRowView;

                    // Display the row
                    System.Console.WriteLine(string.Format("{0} {1} {2} Kb"
                        row["Mailbox"].ToString().PadRight(55), 
                        row["Messages"].ToString().PadLeft(8), 
                        row["Size"].ToString().PadLeft(10)));

                    // Add the size and message count to our totals
                    TotalMessages += Convert.ToInt32(row["Messages"]);
                    TotalSize += Convert.ToInt64(row["Size"]);
                }

                // Write a row of dashes
                System.Console.WriteLine("".PadRight(78'-'));

                // Write the totals
                System.Console.WriteLine(string.Format("{0} {1} {2} Kb"
                    "Total".PadRight(55), 
                    TotalMessages.ToString().PadLeft(8), 
                    TotalSize.ToString().PadLeft(10)));

                // Write the XML to a file if we want to
                ds.WriteXml("Mailboxes.xml");        
            }

            // Catch any problems and show a message!
            catch(Exception e)
            {
                System.Console.WriteLine("Error : " + e.Message.ToString());
            }
        }
    }
}
 

This is how it displays its output to the console.

If you write the data to a XML file as the above example does this is how it may appear.

xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Mailboxes>
    <Mailbox>WeeThings</Mailbox>
    <Messages>742</Messages>
    <Size>41596</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>SMTP (SBS2003-{7390D6EA-A466-417D-A461-ADEA24553CB8})</Mailbox>
    <Messages>0</Messages>
    <Size>0</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>worldnet</Mailbox>
    <Messages>11</Messages>
    <Size>51</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Paradise</Mailbox>
    <Messages>25</Messages>
    <Size>80</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>SystemMailbox{7390D6EA-A466-417D-A461-ADEA24553CB8}</Mailbox>
    <Messages>401</Messages>
    <Size>361</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Art</Mailbox>
    <Messages>53</Messages>
    <Size>333</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Chris Crowe [MVP]</Mailbox>
    <Messages>20</Messages>
    <Size>170</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Pam Elston</Mailbox>
    <Messages>1052</Messages>
    <Size>20852</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Stocks</Mailbox>
    <Messages>33</Messages>
    <Size>607</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>stuff</Mailbox>
    <Messages>106</Messages>
    <Size>1716</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>TradeMe</Mailbox>
    <Messages>287</Messages>
    <Size>1846</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>chris crowe</Mailbox>
    <Messages>4201</Messages>
    <Size>239183</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>IISFAQMailBoxes</Mailbox>
    <Messages>338</Messages>
    <Size>878</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>WeeThings_Trademe</Mailbox>
    <Messages>16</Messages>
    <Size>278</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>PamStocks</Mailbox>
    <Messages>94</Messages>
    <Size>160</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Pets</Mailbox>
    <Messages>20</Messages>
    <Size>148</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Chris Crowe</Mailbox>
    <Messages>14416</Messages>
    <Size>221939</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>IISMVP</Mailbox>
    <Messages>15</Messages>
    <Size>638</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>CarryingABitTooMuch</Mailbox>
    <Messages>19</Messages>
    <Size>1056</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>chris_iisfaq</Mailbox>
    <Messages>4944</Messages>
    <Size>48027</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Forums</Mailbox>
    <Messages>2</Messages>
    <Size>4</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Test</Mailbox>
    <Messages>4</Messages>
    <Size>5</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>System Attendant</Mailbox>
    <Messages>0</Messages>
    <Size>0</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>psoriasis</Mailbox>
    <Messages>3</Messages>
    <Size>5</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Holiday</Mailbox>
    <Messages>959</Messages>
    <Size>24704</Size>
  </Mailboxes>
  <Mailboxes>
    <Mailbox>Braindump</Mailbox>
    <Messages>14</Messages>
    <Size>121</Size>
  </Mailboxes>
</NewDataSet>

IIS - Using WMI and VBScript to Change HTTP Compression Settings in IIS 6

I found an interesting piece of code online for adjusting the IIS compression settings in IIS 6 using WMI and VBScript on WindowsITPro - although you must be a registered user you can download the code.

See http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/44335/44335.html

Or just incase the code is gone click here


IIS - Creating Web Sites and AppPools using WMI ( C# sample code )

I came across a very good example of creating Web Sites with custom App Pools in c# using WMI by a guy called Ramesh Raman's who has a blog at MSDN blogs. It it appears he no longer updates it since the last entry is dated July, 2004

He had an example of using the WMI Provider and XML to create a new web site with a complete description of the process of each step taken:

Using the WMI Provider to Configure IIS 6.0 - A Data Driven Approach
http://blogs.msdn.com/ramesh_r/archive/2004/03/24/95109.aspx

For just the code (which was updated to include the creation of App Pools and Virtual Directories) see:

http://blogs.msdn.com/ramesh_r/articles/170665.aspx

For a copy of the code click here (just incase it disappears) - please note you should right click and save-as as you can not view it as IE will try to render it as XML and fail (although you can then do a view-source to see the code)


Step/Step - An example of updating a Windows Sharepoint Server List from c#

1) Open Visual Studio.NET 2003

2) New Project (We will create a console application in this demo)

3) Name your project "GetListItems"

4) Right Click on "References" under the Project and select "Add Web Reference"

5) In the URL field type the path to your Windows SharePoint Services Site that contains the list you want to use.

Each site is different and only contains the lists for the particular child site.

For example the root site could be called "http://sharepoint.mysite.com" and you could have a sub site called "Test" which is accessible via "http://sharepoint.mysite.com/Test"

So type in your URL and append the following "_vti_bin/lists.asmx"

So if you were going to the "Test" child site your URL would be like this:

http://sharepoint.mysite.com/Test/_vti_bin/lists.asmx

You may be prompted to log onto your SharePoint site when do perform this action.

6) Click on "Go" and the Add Web Reference Dialog should display that it found one service and display you some available operations.

7) Click on "Add Reference"

8) Now you should end up with a new Web Reference Node in the Solution Explorer and your actual Web Reference which may have a funny name like "com.mysite.sharepoint"

9) Right click on the Web Reference and rename it to something simple like "SharePoint", this is what we will use to reference the web service in code.

10) Right click on the Web Reference and select "Properties" and change the "URL Behavior" to "dynamic"

This will add a "app.config" to the project and populate an appSettings item in the config file so that the URL is dynamically loaded from the "app.config" file and not hard coded into the source of the proxy stub that was created.

<?xml version="1.0encoding="utf-8"?>
<configuration>
     <appSettings>
           <add key="GetListItems.Sharepoint.Listsvalue="http://sharepoint.mysite.com/Test/_vti_bin/lists.asmx"/>
     </appSettings>
</configuration>

11) Open the Class1.cs file in the editor and enter the following:

using System;
using System.Net;
using System.Xml;

namespace GetListItems
{
    /// 
    /// Summary description for Class1.
    /// 

    class Class1
    {
        /// 
        /// The main entry point for the application.
        /// 

        [STAThread]
        static void Main(string[] args)
        {
            string Username="UserName";
            string Password="Password";
            string Domain="Domain";
            string ListName = "ListName";

            Sharepoint.Lists ListsService = new Sharepoint.Lists();
            ListsService.Credentials = new NetworkCredential(Username, Password, Domain);

            // Create a new XML document to hold the updates we are going to perform
            XmlDocument doc = new XmlDocument();
            XmlElement updates = doc.CreateElement("Batch");
            updates.SetAttribute("OnError""Continue");

            // We need to Create a Method Tag for each row we are going to update.
            XmlElement UpdatesMethod = doc.CreateElement("Method");
            UpdatesMethod.SetAttribute("ID""1");
            UpdatesMethod.SetAttribute("Cmd""Update");
            updates.AppendChild(UpdatesMethod);

            // We need to update a particular row based on its internal ID.

            XmlElement UpdatesField1 = doc.CreateElement("Field");
            UpdatesField1.SetAttribute("Name""ID");        // Which record to update
            UpdatesField1.InnerText = "1";                    // is defined here
            UpdatesMethod.AppendChild(UpdatesField1);

            // We are going to update the field called "Status"

            XmlElement UpdatesField2 = doc.CreateElement("Field");
            UpdatesField2.SetAttribute("Name""Status");    // Which field to update
            UpdatesField2.InnerText = "Status is OK";        // The actual new value
            UpdatesMethod.AppendChild(UpdatesField2);
        
            // Call the web service to update the list items
            XmlNode Result = ListsService.UpdateListItems(ListName, updates);

            ListsService.Dispose();

            Console.WriteLine("The record has been updated!");

            // Sleep for a moment so we can see the results
            System.Threading.Thread.Sleep(5000);
        }
    }
}

Make sure you populate the Username, Password, Domain, and ListName variables above. You also need to make sure that the field “Status” exists in the particular list that you are updating. If it does not you will need to change it to a field that does exist.

For some sample code that will allow you to display the attribute names in a list see - /archive/2005/08/10/197.aspx

The XmlNode called Result should be parsed to locate errors that may have occurred during the update.


IIS - Scripts - WMI - Enumerate all virtual directories on the local server

The following script will allow you to enumerate the names of the Virtual Directories on the current machine.

Save the following script to a .VBS file extension and execute using the following from a CMD.exe prompt.

cscript MyScript.vbs

Dim IISObj, strQuery, Item

Set IISObj = GetObject("winmgmts://./root/MicrosoftIISv2")
strQuery = "SELECT * FROM IIsWebVirtualDir" 
For Each Item In IISObj.ExecQuery(strQuery)
  WScript.echo Item.Name
Next

Example Output

W3SVC/1/ROOT
W3SVC/1/ROOT/_vti_bin
W3SVC/1/ROOT/Backup
W3SVC/1/ROOT/CertControl
W3SVC/1/ROOT/CertEnroll
W3SVC/1/ROOT/CertSrv
W3SVC/1/ROOT/ClientHelp
W3SVC/1/ROOT/ConnectComputer
W3SVC/1/ROOT/Exadmin
W3SVC/1/ROOT/Exchange
W3SVC/1/ROOT/exchange-oma
W3SVC/1/ROOT/ExchWeb
W3SVC/1/ROOT/ExchWeb/bin
W3SVC/1/ROOT/ExchWeb/bin/auth
W3SVC/1/ROOT/ExchWeb/bin/spell
W3SVC/1/ROOT/IssueVisionDeployWebCS
W3SVC/1/ROOT/IssueVisionWebCS
W3SVC/1/ROOT/Microsoft-Server-ActiveSync

IIS - Scripts - WMI - Enumerate Application Pools on Local Machine

The following script will allow you to enumerate the Names of the Application Pools on the current machine.

Save the following script to a .VBS file extension and execute using the following from a CMD.exe prompt.

cscript MyScript.vbs

Dim locatorObj, ProviderObj, Pools, strQuery

Set locatorObj = CreateObject("WbemScripting.SWbemLocator")
Set ProviderObj = locatorObj.ConnectServer(".", "root/MicrosoftIISv2")

strQuery = "Select * from IIsApplicationPool"
For Each Item In ProviderObj.ExecQuery(strQuery)
    WScript.Echo Replace(Item.Name, "W3SVC/AppPools/", "")
Next


Example Output

DefaultAppPool
ExchangeApplicationPool
ExchangeMobileBrowseApplicationPool
MSSharePointAppPool
MyWineCellar
StsAdminAppPool
WMS App Pool
Blog.crowe.co.nz