共用方式為


ConfigurationSectionWithCollection.Get 方法

從組態區段擷取集合的指定成員。

語法

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

參數

名稱 描述
CollectionName string值,其中包含將 (擷取的集合名稱,例如「Modules」) 。 集合名稱可以代表巢狀集合,而且可以使用索引。 索引可以是以零起始的整數索引或字串 (,例如 [9] 或 「KeyProperty='Value'」) 。 如需詳細資訊,請參閱<備註>一節。 注意:CollectionName是組態檔中找到的區段名稱,而不是對應 WMI (類別的名稱,例如「Modules」、「ModulesSection」) 。
ElementIdentifier string值,指定要擷取之集合專案的索引鍵屬性和值。 字串的格式必須是 「KeyProperty1='Value1',KeyProperty2='Value2',...」 (,例如 「Name='RoleManager'」) 。
CollectionElement CollectionElement物件變數,擷取的集合專案將會放在其中 (, oModule 例如) 。

傳回值

void.

備註

當您只想擷取集合的一個成員時,這個方法很有用。

下列範例示範 參數的 CollectionName 語法變化。

下列語法顯示 CollectionName 使用字串型 「KeyProperty='Value'」 索引的參數,並指定巢狀集合:

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

您可以使用以零起始的索引來指定相同的值:

traceFailedRequests[1].TraceAreas.TraceAreas

ElementIdentifier如果 參數為 "provider='ASP'"CollectionElement 輸出變數為 oTraceAreaElement ,則方法的完整呼叫 Get 看起來可能類似下列語法:

oSection.Get _

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

"provider='ASP'", oTraceAreaElement

下列語法顯示以零起始索引的完整呼叫:

oSection.Get _

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

"provider='ASP'", oTraceAreaElement

範例

下列範例會從 <modules> ApplicationHost.config 檔案的 區段擷取模組的名稱和類型 RoleManager

' 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  
  

規格需求

類型 描述
Client - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10上的 IIS 10.0
伺服器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016上的 IIS 10.0
產品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 檔案 WebAdministration.mof

另請參閱

CollectionElement 類別
ConfigurationSectionWithCollection 類別
ModuleAction 類別
ModulesSection 類別
TraceAreaElement 類別
TraceFailedRequestsSection 類別
TraceUrl 類別
TraceUrlAreaSettings 類別