如何创建 Windows PowerShell 提供者

本节描述如何构建 Windows PowerShell 提供者。 Windows PowerShell 提供者可以从两个角度来看待。 对用户来说,提供者代表一组存储的数据。 例如,存储的数据可以是互联网信息服务(IIS)元数据库、Microsoft Windows 注册表、Windows 文件系统、Active Directory,以及 Windows PowerShell 存储的变量和别名数据。

对开发者来说,Windows PowerShell 提供者是用户与用户需要访问的数据之间的接口。 从这个角度看,本节描述的每种提供者类型都支持一组特定的基类和接口,使 Windows PowerShell 运行时能够以统一的方式向用户暴露某些 cmdlet。

Windows PowerShell 提供的提供者

Windows PowerShell 提供了多个提供者(如文件系统提供者、注册表提供者和别名提供者)用于访问已知数据存储。 如需了解 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 驱动器暴露提供者 cmdlet

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运行时能够初始化和取消初始化该提供者。
创建 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 程序员指南