擷取原始和格式化效能資料物件的檔

下列主題描述如何擷取動態建立原始或格式化資料物件的線上程式設計檔。

WMI 包含一些追蹤效能的物件。 衍生自 Win32_PerfRawData 的 類別包含未經處理或「未編碼」的效能資料, 而且效能計數器提供者支援。 相反地,衍生自 Win32_PerfFormattedData 的類別包含「已操作」或格式化的資料,且受 格式化效能資料提供者支援。

不過,這兩個提供者都支援數個動態建立的子類別。 由於屬性會在執行時間新增,因此這些類別可能包含未記載的屬性。 您可以使用下列程式碼來識別給定動態建立類別具有哪些屬性。

擷取動態建立類別的描述

  1. 建立專案的實例,並將修改的限定詞設定為 true。

    $osClass = New-Object System.Management.ManagementClass Win32_ClassNameHere  
    $osClass.Options.UseAmendedQualifiers = $true
    
  2. 擷取 類別的屬性。

    $properties = $osClass.Properties  
    "This class has {0} properties as follows:" -f $properties.count
    
  3. 顯示內容。

    foreach ($property in $properties) {  
    "Property Name: {0}" -f $property.Name  
    "Description:   {0}" -f $($property.Qualifiers["Description"].Value)  
    "Type:          {0}" -f $property.Type  
    "-------"
    }
    

下列程式碼會擷取指定 之 Win32_PerfFormattedData 物件的屬性描述。

$osClass = New-Object System.Management.ManagementClass Win32_PerfFormattedData_APPPOOLCountersProvider_APPPOOLWAS  
$osClass.Options.UseAmendedQualifiers = $true  
  
# Get the Properties in the class  
$properties = $osClass.Properties  
"This class has {0} properties as follows:" -f $properties.count  
  
  
# display the Property name, description, type, qualifiers and instance values  
  
foreach ($property in $properties) {  
"Property Name: {0}" -f $property.Name  
"Description:   {0}" -f $($property.Qualifiers["Description"].Value)  
"Type:          {0}" -f $property.Type  
"-------"  
}