Skip to content

Latest commit

 

History

History
180 lines (165 loc) · 10.2 KB

File metadata and controls

180 lines (165 loc) · 10.2 KB
description Provider cmdlet dynamic parameters
ms.date 09/13/2016
title Provider cmdlet dynamic parameters

Provider cmdlet dynamic parameters

Providers can define dynamic parameters that are added to a provider cmdlet when the user specifies a certain value for one of the static parameters of the cmdlet. For example, a provider can add different dynamic parameters based on what path the user specifies when they call the Get-Item or Set-Item provider cmdlets.

Dynamic Parameter Methods

Dynamic parameters are defined by implementing one of the dynamic parameter methods, such as the System.Management.Automation.Provider.ItemCmdletProvider.GetItemDynamicParameters* and System.Management.Automation.Provider.SetItemDynamicParameters.SetItemDynamicParameters* methods. These methods return an object that has public properties that are decorated with attributes similar to those of stand-alone cmdlets. Here is an example of an implementation of the System.Management.Automation.Provider.ItemCmdletProvider.GetItemDynamicParameters* method taken from the Certificate provider:

protected override object GetItemDynamicParameters(string path)
{
    return new CertificateProviderDynamicParameters();
}

Unlike the static parameters of provider cmdlets, you can specify the characteristics of these parameters in the same way that parameters are defined in stand-alone cmdlets. Here is an example of a dynamic parameter class taken from the Certificate provider:

internal sealed class CertificateProviderDynamicParameters
{
  /// <summary>
  /// Dynamic parameter the controls whether we only return
  /// code signing certs.
  /// </summary>
  [Parameter()]
  public SwitchParameter CodeSigningCert
  {
    get
    {
      {
        return codeSigningCert;
      }
    }

    set
    {
      {
        codeSigningCert = value;
      }
    }
  }

    private SwitchParameter codeSigningCert = new SwitchParameter();
}

Dynamic Parameters

Here is a list of the static parameters that can be used to add dynamic parameters.

  • Clear-Content cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Clear-Clear cmdlet by implementing the System.Management.Automation.Provider.IContentCmdletProvider.ClearContentDynamicParameters* method.

  • Clear-Item cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Clear-Item cmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.ClearItemDynamicParameters* method.

  • Clear-ItemProperty cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Clear-ItemProperty cmdlet by implementing the System.Management.Automation.Provider.IPropertyCmdletProvider.ClearPropertyDynamicParameters* method.

  • Copy-Item cmdlet - You can define dynamic parameters that are triggered by the Path, Destination, and Recurse parameters of the Copy-Item cmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.CopyItemDynamicParameters* method.

  • Get-ChildItem cmdlet - You can define dynamic parameters that are triggered by the Path and Recurse parameters of the Get-ChildItem cmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.GetChildItemsDynamicParameters* and System.Management.Automation.Provider.ContainerCmdletProvider.GetChildNamesDynamicParameters* methods.

  • Get-Content cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Get-Content cmdlet by implementing the System.Management.Automation.Provider.IContentCmdletProvider.GetContentReaderDynamicParameters* method.

  • Get-Item cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Get-Item cmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.GetItemDynamicParameters* method.

  • Get-ItemProperty cmdlet - You can define dynamic parameters that are triggered by the Path and Name parameters of the Get-ItemProperty cmdlet by implementing the System.Management.Automation.Provider.IPropertyCmdletProvider.GetPropertyDynamicParameters* method.

  • Invoke-Item cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Invoke-Item cmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.InvokeDefaultActionDynamicParameters* method.

  • Move-Item cmdlet - You can define dynamic parameters that are triggered by the Path and Destination parameters of the Move-Item cmdlet by implementing the System.Management.Automation.Provider.NavigationCmdletProvider.MoveItemDynamicParameters* method.

  • New-Item cmdlet - You can define dynamic parameters that are triggered by the Path, ItemType, and Value parameters of the New-Item cmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.NewItemDynamicParameters* method.

  • New-ItemProperty cmdlet - You can define dynamic parameters that are triggered by the Path, Name, PropertyType, and Value parameters of the New-ItemProperty cmdlet by implementing the System.Management.Automation.Provider.IDynamicPropertyCmdletProvider.NewPropertyDynamicParameters* method.

  • New-PSDrive cmdlet - You can define dynamic parameters that are triggered by the System.Management.Automation.PSDriveInfo object returned by the New-PSDrive cmdlet by implementing the System.Management.Automation.Provider.DriveCmdletProvider.NewDriveDynamicParameters* method.

  • Remove-Item cmdlet - You can define dynamic parameters that are triggered by the Path and Recurse parameters of the Remove-Item cmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.RemoveItemDynamicParameters* method.

  • Remove-ItemProperty cmdlet - You can define dynamic parameters that are triggered by the Path and Name parameters of the Remove-ItemProperty cmdlet by implementing the System.Management.Automation.Provider.IDynamicPropertyCmdletProvider.RemovePropertyDynamicParameters* method.

  • Rename-Item cmdlet - You can define dynamic parameters that are triggered by the Path and NewName parameters of the Rename-Item cmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.RenameItemDynamicParameters* method.

  • Rename-ItemProperty - You can define dynamic parameters that are triggered by the Path, Name, and NewName parameters of the Rename-ItemProperty cmdlet by implementing the System.Management.Automation.Provider.IDynamicPropertyCmdletProvider.RenamePropertyDynamicParameters* method.

  • Set-Content cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Set-Content cmdlet by implementing the System.Management.Automation.Provider.IContentCmdletProvider.GetContentWriterDynamicParameters* method.

  • Set-Item cmdlet - You can define dynamic parameters that are triggered by the Path and Value parameters of the Set-Item cmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.SetItemDynamicParameters* method.

  • Set-ItemProperty cmdlet - You can define dynamic parameters that are triggered by the Path and Value parameters of the Set-Item cmdlet by implementing the System.Management.Automation.Provider.IPropertyCmdletProvider.SetPropertyDynamicParameters* method.

  • Test-Path cmdlet - You can define dynamic parameters that are triggered by the Path parameter of the Test-Path cmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.InvokeDefaultActionDynamicParameters* method.

See Also

Writing a Windows PowerShell Provider