8000 HadErrors() returns $true if Send-MailMessage cmdlet is used · Issue #10015 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

HadErrors() returns $true if Send-MailMessage cmdlet is used #10015

@kkbruce

Description

@kkbruce

Steps to reproduce

I user PowerShell Class (version 6.2.1) in .NET Core project, If scripts include Send-MailMessage cmdlet, shell.HadErrors get true:

using (PowerShell shell = PowerShell.Create())
{
    shell.AddScript(scripts);
    var results = shell.Invoke();

        if (shell.HadErrors)
        {
            _logger.LogTrace($"shell.HadErrors is {shell.HadErrors}");
        }
}

I trace shell.Streams object, only Warning count 1, other PSDataStreams properties (Error ...) count 0.

Warning message is new System.Collections.Generic.ICollectionDebugView<System.Management.Automation.WarningRecord>(shell.Streams.Warning._data).Items[0] {The command 'Send-MailMessage' is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage at this time. See https://aka.ms/SendMailMessage for more information.} System.Management.Automation.WarningRecord

Expected behavior

shell.HadErrors is false.

Actual behavior

shell.HadErrors is true.

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.17134.765
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.765
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0