Deprecation of cmdlets
Until PowerShell 3.0, if you shipped a cmdlet there was no good way to deprecate it. Cmdlet developers can use the .NET ObsoleteAttribute now to let users know that they should not use a cmdlet anymore. In the following example, the cmdlet can run but it will issue a warning that another cmdlet should be used from now on. This gives the user time to prepare for the change and fix any scripts dependent on old commands.
$code = @'
[Obsolete("This cmdlet is obsolete. Please use Get-Bar instead.")]
public class ObsoleteCmdlet : PSCmdlet
protected override void ProcessRecord()
#compile this code into the ObsoleteCmdlet.dll
PS> Add-Type -TypeDefinition $code -OutputAssembly $env:TEMP\ObsoleteCmdlet.dll
# Import the module and run our cmdlet
PS> Import-Module $env:TEMP\ObsoleteCmdlet.dll
WARNING: This cmdlet is obsolete. Please use Get-Bar instead.
When you ship the next version of your cmdlet you can change the behavior of the Obsolete attribute, by using another constructor, and throw an error instead of a warning:
# [Obsolete("This cmdlet is obsolete. Please use Get-Bar instead.",true)]
This cmdlet is obsolete. Please use Get-Bar instead.
At line:1 char:1
+ CategoryInfo : InvalidOperation: (Get-Foo:String) , RuntimeException
+ FullyQualifiedErrorId : UseOfDeprecatedCmdlet
It would be great to have this attribute in advanced functions and even on parameters. I logged a suggestion on connect about this, vote it up if you like it.