共用方式為


如何建立 Windows PowerShell 提供者

本節說明如何建置 Windows PowerShell 提供者。 Windows PowerShell 提供者可從兩種角度來看待。 對使用者而言,提供者代表一組儲存的資料。 例如,儲存的資料可以是網際網路資訊服務(IIS)Metabase、Microsoft Windows 登錄檔、Windows 檔案系統、Active Directory,以及 Windows PowerShell 儲存的變數和別名資料。

對開發者而言,Windows PowerShell 提供者是使用者與使用者所需存取資料之間的介面。 從這個角度來看,本節描述的每種提供者類型都支援一組特定的基底類別與介面,讓 Windows PowerShell 執行環境能以共通方式向使用者揭露特定 cmdlet。

由 Windows PowerShell 提供的提供者

Windows PowerShell 提供多種提供者(如 FileSystem 提供者、登錄檔提供者及別名提供者)用於存取已知資料儲存。 欲了解更多 Windows PowerShell 提供的提供者資訊,請使用以下指令存取線上說明:

附註>Get-Help about_Providers

使用 Windows PowerShell 路徑存取儲存的資料

Windows PowerShell 提供者可透過 Windows PowerShell 路徑程式化存取 Windows PowerShell 執行環境及指令。 大多數情況下,這些路徑是用來直接透過提供者存取資料。 然而,有些路徑可以解析為提供者內部路徑,允許指令小程式使用非 Windows PowerShell 應用程式介面(API)來存取資料。 欲了解更多關於 Windows PowerShell 提供者如何在 Windows PowerShell 中運作的資訊,請參閱 Windows PowerShell 運作方式

使用 Windows PowerShell 磁碟機暴露提供者指令長

Windows PowerShell 提供者會利用虛擬的 Windows PowerShell 磁碟機公開其支援的 cmdlet。 Windows PowerShell 對 Windows PowerShell 磁碟機套用以下規則:

  • 磁碟機名稱可以是任何字母數字序列。
  • 磁碟機可在路徑上任意有效點指定,稱為「根節點」。
  • 磁碟機可以為任何儲存的資料實作,而不僅限於檔案系統。
  • 每個磁碟機都保留其目前的工作位置,讓使用者在切換磁碟時能保留上下文。

本節中

下表列出包含相互建立的程式碼範例主題。 從第二個主題開始,基本的 Windows PowerShell 提供者可以由 Windows PowerShell 執行時初始化和取消初始化,下一個主題新增存取資料的功能,下一個主題則新增操作資料(儲存資料中的項目)的功能,依此類推。

主題 Definition
設計你的 Windows PowerShell 提供者 本主題討論在實作 Windows PowerShell 提供者前應考慮的事項。 它總結了所使用的 Windows PowerShell 提供者基底類別與介面。
建立一個基本的 Windows PowerShell 提供者 本主題說明如何建立一個 Windows PowerShell 提供者,讓 Windows PowerShell 執行環境能夠初始化與取消初始化該提供者。
建立 Windows PowerShell 磁碟機提供者 本主題說明如何建立一個 Windows PowerShell 提供者,讓使用者能透過 Windows PowerShell 磁碟機存取資料儲存。
建立 Windows PowerShell 項目提供者 本主題說明如何建立一個 Windows PowerShell 提供者,讓使用者能操作資料儲存中的項目。
建立 Windows PowerShell 容器提供者 本主題說明如何建立一個 Windows PowerShell 提供者,讓使用者能在多層資料儲存上工作。
建立 Windows PowerShell 導航提供者 本主題說明如何建立一個 Windows PowerShell 提供者,讓使用者能以階層式方式瀏覽資料儲存中的項目。
建立 Windows PowerShell 內容提供者 本主題將展示如何建立一個 Windows PowerShell 提供者,讓使用者能操作資料儲存中項目的內容。
建立 Windows PowerShell 屬性提供者 本主題說明如何建立一個 Windows PowerShell 提供者,讓使用者能操作資料庫中項目的屬性。

另請參閱

Windows PowerShell 運作原理

Windows PowerShell SDK

Windows PowerShell 程式設計師指南