ConfigurationSectionWithCollection.Get Method [IIS 7 and higher]

IIS 7.0

Retrieves the specified member of a collection from a configuration section.

ConfigurationSectionWithCollection.Get 
   CollectionName, 
   ElementIdentifier, 
   CollectionElement;
ConfigurationSectionWithCollection.Get 
CollectionName, 
ElementIdentifier, 
CollectionElement

Name

Description

CollectionName

A string value that contains the name of the collection that will be retrieved (for example, "Modules"). The collection name can represent a nested collection and can use indexes. The index can be either a zero-based integer index or a string (for example, [9] or "KeyProperty='Value'"). For more information, see the Remarks section.

NoteNote:
The CollectionName is the name of the section as it is found in the configuration file, not the name of the corresponding WMI class (for example, "Modules", not "ModulesSection").

ElementIdentifier

A string value that specifies a key property and value of the collection element to be retrieved. The string must be in the format "KeyProperty1='Value1',KeyProperty2='Value2',…" (for example, "Name='RoleManager'").

CollectionElement

A CollectionElement object variable into which the retrieved collection element will be put (for example, oModule).

This method is useful when you want to retrieve only one member of a collection.

The following examples demonstrate syntax variations for the CollectionName parameter.

The following syntax shows a CollectionName parameter that uses a string-based "KeyProperty='Value'" index and specifies a nested collection:

traceFailedRequests[path='Rule_2'].TraceAreas.TraceAreas

You can specify the same value with a zero-based index:

traceFailedRequests[1].TraceAreas.TraceAreas

If the ElementIdentifier parameter is "provider='ASP'" and the CollectionElement output variable is oTraceAreaElement, the complete call to the Get method might look like the following syntax:

oSection.Get _

"traceFailedRequests[path='Rule_2'].TraceAreas.TraceAreas", _

"provider='ASP'", oTraceAreaElement

The following syntax shows the complete call with a zero-based index:

oSection.Get _

"traceFailedRequests[1].TraceAreas.TraceAreas", _

"provider='ASP'", oTraceAreaElement

The following example retrieves the name and type of the RoleManager module from the <modules> section of the ApplicationHost.config file.

' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

' First, get the <modules> section by using the inherited 
' WMI Get method on the WMI class name of the section
' (that is, "ModulesSection").
Set oSection = oWebAdmin.Get( _
    "ModulesSection.Path='MACHINE/WEBROOT/APPHOST/'," & _
    "Location=''")

' Display the path. 
WScript.Echo "Path: " & oSection.Path_.RelPath

' Retrieve the RoleManager member of the collection.
' This is the ConfigurationSectionWithCollection.Get method,
' so use the collection name found in the configuration file
' (that is, "Modules").
oSection.Get "Modules", "Name='RoleManager'", oModule

' Display the module name and type.
WScript.Echo "Module Name: " & oModule.Name
WScript.Echo "Module Type: " & oModule.Type
 
' Output:
' Path: ModulesSection.Location="",Path="MACHINE/WEBROOT/APPHOST/"
' Module Name: RoleManager
' Module Type: System.Web.Security.RoleManagerModule

Type

Description

Client

Requires IIS 7 on Windows Vista.

Server

Requires IIS 7 on Windows Server 2008.

Product

IIS 7

MOF file

WebAdministration.mof

Community Additions

ADD
Show: