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-Contentcmdlet - You can define dynamic parameters that are triggered by thePathparameter of the Clear-Clear cmdlet by implementing the System.Management.Automation.Provider.IContentCmdletProvider.ClearContentDynamicParameters* method.Clear-Itemcmdlet - You can define dynamic parameters that are triggered by thePathparameter of theClear-Itemcmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.ClearItemDynamicParameters* method.Clear-ItemPropertycmdlet - You can define dynamic parameters that are triggered by thePathparameter of theClear-ItemPropertycmdlet by implementing the System.Management.Automation.Provider.IPropertyCmdletProvider.ClearPropertyDynamicParameters* method.Copy-Itemcmdlet - You can define dynamic parameters that are triggered by thePath,Destination, andRecurseparameters of theCopy-Itemcmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.CopyItemDynamicParameters* method.Get-ChildItemcmdlet - You can define dynamic parameters that are triggered by thePathandRecurseparameters of theGet-ChildItemcmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.GetChildItemsDynamicParameters* and System.Management.Automation.Provider.ContainerCmdletProvider.GetChildNamesDynamicParameters* methods.Get-Contentcmdlet - You can define dynamic parameters that are triggered by thePathparameter of theGet-Contentcmdlet by implementing the System.Management.Automation.Provider.IContentCmdletProvider.GetContentReaderDynamicParameters* method.Get-Itemcmdlet - You can define dynamic parameters that are triggered by thePathparameter of theGet-Itemcmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.GetItemDynamicParameters* method.Get-ItemPropertycmdlet - You can define dynamic parameters that are triggered by thePathandNameparameters of theGet-ItemPropertycmdlet by implementing the System.Management.Automation.Provider.IPropertyCmdletProvider.GetPropertyDynamicParameters* method.Invoke-Itemcmdlet - You can define dynamic parameters that are triggered by thePathparameter of theInvoke-Itemcmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.InvokeDefaultActionDynamicParameters* method.Move-Itemcmdlet - You can define dynamic parameters that are triggered by thePathandDestinationparameters of theMove-Itemcmdlet by implementing the System.Management.Automation.Provider.NavigationCmdletProvider.MoveItemDynamicParameters* method.New-Itemcmdlet - You can define dynamic parameters that are triggered by thePath,ItemType, andValueparameters of theNew-Itemcmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.NewItemDynamicParameters* method.New-ItemPropertycmdlet - You can define dynamic parameters that are triggered by thePath,Name,PropertyType, andValueparameters of theNew-ItemPropertycmdlet by implementing the System.Management.Automation.Provider.IDynamicPropertyCmdletProvider.NewPropertyDynamicParameters* method.New-PSDrivecmdlet - You can define dynamic parameters that are triggered by the System.Management.Automation.PSDriveInfo object returned by theNew-PSDrivecmdlet by implementing the System.Management.Automation.Provider.DriveCmdletProvider.NewDriveDynamicParameters* method.Remove-Itemcmdlet - You can define dynamic parameters that are triggered by thePathandRecurseparameters of theRemove-Itemcmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.RemoveItemDynamicParameters* method.Remove-ItemPropertycmdlet - You can define dynamic parameters that are triggered by thePathandNameparameters of theRemove-ItemPropertycmdlet by implementing the System.Management.Automation.Provider.IDynamicPropertyCmdletProvider.RemovePropertyDynamicParameters* method.Rename-Itemcmdlet - You can define dynamic parameters that are triggered by thePathandNewNameparameters of theRename-Itemcmdlet by implementing the System.Management.Automation.Provider.ContainerCmdletProvider.RenameItemDynamicParameters* method.Rename-ItemProperty- You can define dynamic parameters that are triggered by thePath,Name, andNewNameparameters of theRename-ItemPropertycmdlet by implementing the System.Management.Automation.Provider.IDynamicPropertyCmdletProvider.RenamePropertyDynamicParameters* method.Set-Contentcmdlet - You can define dynamic parameters that are triggered by thePathparameter of theSet-Contentcmdlet by implementing the System.Management.Automation.Provider.IContentCmdletProvider.GetContentWriterDynamicParameters* method.Set-Itemcmdlet - You can define dynamic parameters that are triggered by thePathandValueparameters of theSet-Itemcmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.SetItemDynamicParameters* method.Set-ItemPropertycmdlet - You can define dynamic parameters that are triggered by thePathandValueparameters of theSet-Itemcmdlet by implementing the System.Management.Automation.Provider.IPropertyCmdletProvider.SetPropertyDynamicParameters* method.Test-Pathcmdlet - You can define dynamic parameters that are triggered by thePathparameter of theTest-Pathcmdlet by implementing the System.Management.Automation.Provider.ItemCmdletProvider.InvokeDefaultActionDynamicParameters* method.