Search Wiki:

DoNotUseConsoleApi


TypeName DoNotUseConsoleApi
CheckId PS1015
Error-Level Error
Category Microsoft.PowerShell
Certainty 80%
BreakingChange Non-breaking
Cause A cmdlet uses the System.Console API.
Rule descriptionCmdlets that use the System.Console API do not work properly on hosts that do not have an associated console (such as the remoting host or ISE host). For informational messages, use the WriteWarning, WriteVerbose, or WriteDebug methods of System.Management.Automation.Cmdlet. To prompt for user input, use the System.Management.Automation.Host API.
How to fix violations Do not use System.Console API in your cmdlets.
When to exclude warnings Do not suppress warnings from this rule.
Related rules DoNotCallCertainHostMethods
See also FxCop Rules for Windows PowerShell

Examples


// Example of a cmdlet that violates this rule.
[Cmdlet("Start", "Power")]
public class StartPowerCommand : PSCmdlet
{
    protected override void BeginProcessing()
    {
        Console.Write("Preparing to start...");
        // ...
    }
}

// Example of a cmdlet that follows this rule.
[Cmdlet("Start", "Power")]
public class StartPowerCommand : PSCmdlet
{
    protected override void BeginProcessing()
    {
        this.WriteWarning("Preparing to start...");
        // ...
    }
}

Back to FxCop Rules for Windows PowerShell.
Last edited Mar 26 2010 at 4:10 PM  by JuneB, version 1
Updating...
Page view tracker