如何创建 Windows PowerShell 提供程序

本部分介绍如何生成 Windows PowerShell 提供程序。 可以通过两种方式考虑 Windows PowerShell 提供程序。 对用户,提供程序表示一组存储的数据。 例如,存储的数据可以是 Internet Information Services (IIS) 元数据库、Microsoft Windows 注册表、Windows 文件系统、Active Directory 以及 Windows PowerShell 存储的变量和别名数据。

对于开发人员,Windows PowerShell 提供程序是用户与用户需要访问的数据之间的接口。 从这个角度看,本节中描述的每种类型的提供程序都支持一组特定的基类和接口,这些基类和接口允许 Windows PowerShell 运行时以常用方式向用户公开某些 cmdlet。

Windows PowerShell 提供的提供程序

Windows PowerShell 提供用于访问已知数据存储的多个提供程序(例如 FileSystem 提供程序、注册表提供程序和别名提供程序)。 有关 Windows PowerShell 提供的提供程序的详细信息,请使用以下命令访问联机帮助:

PS>Get-Help about_Providers

使用 Windows PowerShell 路径访问存储的数据

Windows PowerShell 提供程序可通过使用 Windows PowerShell 路径以编程方式访问 Windows PowerShell 提供程序和命令。 大多数情况下,这些路径用于通过提供程序直接访问数据。 但是,某些路径可以解析为提供程序内部路径,允许 cmdlet 使用非 Windows PowerShell 应用程序编程接口(API)访问数据。 有关 Windows PowerShell 提供程序如何在 Windows PowerShell 中运行的详细信息,请参阅 Windows PowerShell 的工作原理

使用 Windows PowerShell 驱动器公开提供程序 Cmdlet

Windows PowerShell 提供程序使用虚拟 Windows PowerShell 驱动器公开其支持的 cmdlet。 Windows PowerShell 对 Windows PowerShell 驱动器应用以下规则:

  • 驱动器的名称可以是任何字母数字序列。
  • 可以在路径上的任何有效点(称为“root”)指定驱动器。
  • 驱动器可以针对任何存储的数据实现,而不仅仅是文件系统。
  • 每个驱动器保留自己的当前工作位置,允许用户在驱动器之间切换时保留上下文。

本节中

下表列出了包含相互构建的代码示例的主题。 从第二个主题开始,基本 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 提供程序,该提供程序允许用户作数据存储中项的属性。

另请参阅

Windows PowerShell 的工作原理

Windows PowerShell SDK

Windows PowerShell 程序员指南