Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Removes the specified element from a collection in a configuration section.
Syntax
ConfigurationSectionWithCollection.Remove collectionName, element;
ConfigurationSectionWithCollection.Remove collectionName, element
Parameters
| Name | Definition | 
|---|---|
| collectionName | A string value that specifies the name of the collection that has an element to be removed. | 
| element | A CollectionElement object that contains the element to be removed. | 
Return Value
This method does not return a value.
Example
The following example displays the names of the handlers for the default Web site, removes the handler element named "CGI-exe" if it is present, and then lists the handler names again. The code will cause the following XML to be added to the <system.webServer> section of the Web.config file for the default Web site:
<handlers>
<remove name="CGI-exe" />
</handlers>
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the default Web site.
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")
' Get the handlers section.
oSite.GetSection "HandlersSection", oHandlersSection
' Display the current handler names.
Wscript.Echo "---[Current Handler List]---"
Call DisplayHandlerNames
' Remove the CGI-exe handler by matching its name.
For Each oHandler In oHandlersSection.Handlers
     If oHandler.Name = "CGI-exe" Then
        oHandlersSection.Remove "Handlers", oHandler
    End If 
Next
' Refresh the oHandlersSection object so that its contents will
' reflect the updated configuration.
oHandlersSection.Refresh_    
 
' List the handler names again to show the change.
Wscript.Echo "---[New Handler List]---"
Call DisplayHandlerNames
' Provide a subroutine to display handler names.
Sub DisplayHandlerNames
    For Each oHandler In oHandlersSection.Handlers
        WScript.Echo "Handler Name: " & oHandler.Name
    Next
    Wscript.Echo
End Sub
Note Calling the Remove_ method updates the underlying configuration store but not the oHandlersSection object that is running in memory. Calling the Refresh_ method on oHandlersSection will ensure that its data is accurate if you need to use it later in the same script.
Requirements
| Type | Description | 
|---|---|
| Client | Requires IIS 7 on Windows Vista. | 
| Server | Requires IIS 7 on Windows Server 2008. | 
| Product | IIS 7 | 
| MOF file | WebAdministration.mof | 
See Also
Reference
ConfigurationSectionWithCollection Class [IIS 7 and higher]