Provider types

Providers define their basic functionality by changing how the provider cmdlets (provided by Windows PowerShell) perform their actions. For example, providers can use the default functionality of the Get-Item cmdlet, or they can change how that cmdlet operates when retrieving items from the data store. The provider functionality described in this topic includes functionality defined by overwriting methods from specific provider base classes and interfaces.

noteNote:
For provider features that are pre-defined by Windows PowerShell, see Windows PowerShell Provider Capabilities.

Drive-Enabled Providers

Drive-enabled providers specify the default drives available to the user and allow the user to add or remove drives. In most cases, providers are drive-enabled providers because they require some default drive to access the data store. However, when writing your own provider you might or might not want to allow the user to create and remove drives.

To create a drive-enabled provider, your provider class must derive from the DriveCmdletProvider class or another class that derives from that class. The DriveCmdletProvider class defines the following methods for implementing the default drives of the provider and supporting the New-PSDrive and Remove-PSDrive cmdlets. In most cases, to support a provider cmdlet you must overwrite the method that the Windows PowerShell engine calls to invoke the cmdlet, such as the NewDrive method for the New-PSDrive cmdlet, and optionally you can overwrite a second method, such as NewDriveDynamicParameters, for adding dynamic parameters to the cmdlet.

  • The InitializeDefaultDrives method defines the default drives that are available to the user whenever the provider is used.

  • The NewDrive and NewDriveDynamicParameters methods defines how your provider supports the New-PSDrive provider cmdlet. This cmdlet allows the user to create drives to access the data store.

  • The RemoveDrive method defines how your provider supports the Remove-PSDrive provider cmdlet. This cmdlet allows the user to remove drives from the data store.

Item-Enabled Providers

Item-enabled providers allow the user to get, set, or clear the items in the data store. An “item” is an element of the data store that the user can access or manage independently. To create an item-enabled provider, your provider class must derive from the ItemCmdletProvider class or another class that derives from that class.

The ItemCmdletProvider class defines the following methods for implementing specific provider cmdlets. In most cases, to support a provider cmdlet you must overwrite the method that the Windows PowerShell engine calls to invoke the cmdlet, such as the ClearItem method for the Clear-Item cmdlet, and optionally you can overwrite a second method, such as ClearItemDynamicParameters, for adding dynamic parameters to the cmdlet.

  • The ClearItem and ClearItemDynamicParameters methods define how your provider supports the Clear-Item provider cmdlet. This cmdlet allows the user to remove of the value of an item in the data store.

  • The GetItem and GetItemDynamicParameters methods define how your provider supports the Get-Item provider cmdlet. This cmdlet allows the user to retrieve data from the data store.

  • The SetItem and SetItemDynamicParameters methods define how your provider supports the Set-Item provider cmdlet. This cmdlet allows the user to update the values of items in the data store.

  • The InvokeDefaultAction and InvokeDefaultAction methods define how your provider supports the Invoke-Item provider cmdlet. This cmdlet allows the user to perform the default action specified by the item.

  • The ItemExists and ItemExistsDynamicParameters methods define how your provider supports the Test-Path provider cmdlet. This cmdlet allows the user to determine if all the elements of a path exist.

In addition to the methods used to implement provider cmdlets, the ItemCmdletProvider class also defines the following methods:

  • The ExpandPath method allows the user to use wildcards when specifying the provider path.

  • The IsValidPath is used to determine if a path is syntactically and semantically valid for the provider.

Container-Enabled Providers

Container-enabled providers allow the user to manage items that are containers. A container is a group of child items under a common parent item. To create a container-enabled provider, your provider class must derive from the ContainerCmdletProvider class or another class that derives from that class.

Important Note:
Container-enabled providers cannot access data stores that contain nested containers. If a child item of a container is another container, you must implement a navigation-enabled provider.

The ContainerCmdletProvider class defines the following methods for implementing specific provider cmdlets. In most cases, to support a provider cmdlet you must overwrite the method that the Windows PowerShell engine calls to invoke the cmdlet, such as the CopyItem method for the Copy-Item cmdlet, and optionally you can overwrite a second method, such as CopyItemDynamicParameters, for adding dynamic parameters to the cmdlet.

In addition to the methods used to implement provider cmdlets, the ContainerCmdletProvider class also defines the following methods:

  • The HasChildItems method can be used by the provider class to determine whether an item has child items.

  • The ConvertPath method can be used by the provider class to create a new provider-specific path from a specified path.

Navigation-Enabled Providers

Navigation-enabled providers allow the user to move items in the data store. To create a navigation-enabled provider, your provider class must derive from the NavigationCmdletProvider class.

The NavigationCmdletProvider class defines the following methods for implementing specific provider cmdlets. In most cases, to support a provider cmdlet you must overwrite the method that the Windows PowerShell engine calls to invoke the cmdlet, such as the MoveItem method for the Move-Item cmdlet, and optionally you can overwrite a second method, such as MoveItemDynamicParameters, for adding dynamic parameters to the cmdlet.

  • The MoveItem and MoveItemDynamicParameters methods define how your provider supports the Move-Item provider cmdlet. This cmdlet allows the user to move an item from one location in the store to another location.

  • The MakePath method defines how your provider supports the Join-Path provider cmdlet. This cmdlet allows the user to combine a parent and child path segment to create a provider-internal path.

In addition to the methods used to implement provider cmdlets, the NavigationCmdletProvider class also defines the following methods:

  • The GetChildName method extracts the name of the child node of a path.

  • The GetParentPath method extracts the parent part of a path.

  • The IsItemContainer method determines whether the item is a container item. In this context, a container is a group of child items under a common parent item.

  • The NormalizeRelativePath method returns a path to an item that is relative to a specified base path.

Content-Enabled Providers

Content-enabled providers allow the user to clear, get, or set the content of items in a data store. For example, the FileSystem provider allows you to clear, get, and set the content of files in the file system. To create a content enabled provider, your provider class must implement the methods of the IContentCmdletProvider interface.

The IContentCmdletProvider interface defines the following methods for implementing specific provider cmdlets. In most cases, to support a provider cmdlet you must overwrite the method that the Windows PowerShell engine calls to invoke the cmdlet, such as the ClearContent method for the Clear-Content cmdlet, and optionally you can overwrite a second method, such as ClearContentDynamicParameters, for adding dynamic parameters to the cmdlet.

Property-Enabled Providers

Property-enabled providers allow the user to manage the properties of the items in the data store. To create a property-enabled provider, your provider class must implement the methods of the IPropertyCmdletProvider and IDynamicPropertyCmdletProvider interfaces. In most cases, to support a provider cmdlet you must overwrite the method that the Windows PowerShell engine calls to invoke the cmdlet, such as the ClearProperty method for the Clear-Property cmdlet, and optionally you can overwrite a second method, such as ClearPropertyDynamicParameters, for adding dynamic parameters to the cmdlet.

The IPropertyCmdletProvider interface defines the following methods for implementing specific provider cmdlets:

The IDynamicPropertyCmdletProvider interface defines the following methods for implementing specific provider cmdlets:

See Also



Show:
© 2014 Microsoft