存取 Interop 命名空間中的數據
關聯提供者可讓 Windows Management Instrumentation(WMI)用戶端瀏覽並擷取來自不同命名空間的設定檔和相關的類別例項。
關聯提供者和類別位於 \\root\interop 命名空間中。 如需更多了解,請參閱 跨命名空間關聯遍歷 和 撰寫關聯提供程序。
關聯提供者會公開標準配置檔,例如電源配置檔。 下列範例使用Power Profile來說明如何透過Interop命名空間探索和存取數據。
Windows PowerShell 提供簡單的機制,以遍歷適當的關聯、擷取裝置設定檔,以及呼叫方法。
列舉根/Interop 命名空間中的配置檔
下列 Windows PowerShell 命令會列舉 Windows 7 計算機上的分散式管理工作組 (DMTF)支援的配置檔:
Get-WmiObject CIM_RegisteredProfile -namespace root\interop
擷取特定裝置配置檔的實例
下列 Windows PowerShell 命令會透過 CIM_RegisteredProfile傳回指定設定檔的所有實例:
Get-WmiObject -namespace root\interop -query "Associators of {CIM_RegisteredProfile.InstanceID='Power Supply'}"
將電源配置檔指派給變數
下列 Windows PowerShell 命令會將電源設定檔實例指派給變數:
$pplan = Get-WmiObject -query "Select * from Win32_PowerPlan" -Namespace root\cimv2\power
列舉電腦上的電源計劃
下列 Windows PowerShell 命令會列舉可用的電源設定檔計劃:
$pplan
呼叫函數
下列 Windows PowerShell 命令會針對電源計劃呼叫 Activate 方法:
$pplan[2].Activate()
相關主題