Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-#2038 Write-Output: {Write-Output @() -NoEnumerate}.Invoke() returns empty Collection<PSObject> #7081

Closed
alx9r opened this issue Jun 15, 2018 · 4 comments
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@alx9r
Copy link

alx9r commented Jun 15, 2018

The behavior of Write-Output has been incorrect since #2038 (see #5955, #5122, #6451, etc.). I'd like for its correct behavior to be restored. It seems like restoring Write-Output to its pre-#2038 implementation wouldn't be entirely sufficient, however. It seems like there's something that changed between version 5.1 and 6.1-preview that affects how the pre-#2038 implementation of Write-Output behave for empty arrays. That is why I'm opening this issue.

For this repro I've implemented Write-Output2 as a stand-in for pre-#2038 Write-Output (see #6451(comment)) . I believe (and it is my intention) that this implementation of Write-Output2 matches the pre-#2038 implementation of Write-Output.

Steps to reproduce

Add-Type '
    using System.Management.Automation;

    [Cmdlet(VerbsCommunications.Write, "Output2")]
    public class WriteOutput2Command : PSCmdlet
    {
        private PSObject[] _inputObjects = null;

        [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromRemainingArguments = true)]
        [AllowNull]
        [AllowEmptyCollection]
        public PSObject[] InputObject
        {
            get { return _inputObjects; }
            set { _inputObjects = value; }
        }

        [Parameter()]
        public SwitchParameter NoEnumerate
        {
            get;
            set;
        }

        protected override void ProcessRecord()
        {
            if (null == _inputObjects)
            {
                WriteObject(_inputObjects);
                return;
            }

            bool enumerate = true;
            if (NoEnumerate.IsPresent)
            {
                enumerate = false;
            }
            foreach (PSObject inputObject in _inputObjects)
            {
                WriteObject(inputObject, enumerate);
            }
        }//processrecord
    }' -PassThru | % Assembly | Import-Module

$c = {Write-Output2 @() -NoEnumerate}.Invoke()
$c.Count

Expected behavior

I expected the Collection<PSObject> returned by .Invoke() to contain a reference to the empty array passed to Write-Output2. I expected that Write-Output -NoEnumerate should be transparent to the object passed to it. Such behavior would match the behavior in version 5.1.

1

Actual behavior

The Collection<PSObject> does not contain anything.

0

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.688
PSEdition                      Core
GitCommitId                    v6.1.0-preview.688
OS                             Microsoft Windows 6.3.9600
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@alx9r alx9r changed the title pre-#2038: {Write-Output @() -NoEnumerate}.Invoke() returns empty collection pre-#2038 Write-Output: {Write-Output @() -NoEnumerate}.Invoke() returns empty collection Jun 15, 2018
@alx9r alx9r changed the title pre-#2038 Write-Output: {Write-Output @() -NoEnumerate}.Invoke() returns empty collection pre-#2038 Write-Output: {Write-Output @() -NoEnumerate}.Invoke() returns empty Collection<PSObject> Jun 15, 2018
@iSazonov iSazonov added Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels Jun 19, 2018
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

2 similar comments
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

No branches or pull requests

2 participants