Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace Microsoft.PowerShell.Commands
[Cmdlet(VerbsCommunications.Write, "Output", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113427", RemotingCapability = RemotingCapability.None)]
public sealed class WriteOutputCommand : PSCmdlet
{
private PSObject[] _inputObjects = null;
private PSObject _inputObjects = null;

/// <summary>
/// Holds the list of objects to be Written
/// </summary>
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromRemainingArguments = true)]
[AllowNull]
[AllowEmptyCollection]
public PSObject[] InputObject
public PSObject InputObject
{
get { return _inputObjects; }
set { _inputObjects = value; }
Expand All @@ -42,22 +42,7 @@ public SwitchParameter NoEnumerate
/// <summary>
/// This method implements the ProcessRecord method for Write-output command
/// </summary>
protected override void ProcessRecord()
{
if (null == _inputObjects)
{
WriteObject(_inputObjects);
return;
}

bool enumerate = true;
if (NoEnumerate.IsPresent)
{
enumerate = false;
}

WriteObject(_inputObjects, enumerate);
}//processrecord
protected override void ProcessRecord() => WriteObject(_inputObjects, !NoEnumerate);
}//WriteOutputCommand
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,8 @@ private void HandleRemainingArguments()
// Set-ClusterOwnerNode -Owners foo,bar
// Set-ClusterOwnerNode foo bar
// Set-ClusterOwnerNode foo,bar
// we unwrap our List, but only if there is a single argument of type object[].
if (valueFromRemainingArguments.Count == 1 && valueFromRemainingArguments[0] is object[])
// we unwrap our List, but only if there is a single argument.
if (valueFromRemainingArguments.Count == 1)
{
cpi.SetArgumentValue(UnboundArguments[0].ArgumentExtent, valueFromRemainingArguments[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ Describe "Write-Output" -Tags "CI" {
$singleCollection | Should Be 1
}
}

Context "Singular objects" {
It "Write-Object -NoEnumerate should not wrap singular objects" {
Write-Output -NoEnumerate 1 | Should BeOfType [int]
1 | Write-Output -NoEnumerate | Should BeOfType [int]
}
}
}
20 changes: 20 additions & 0 deletions test/powershell/engine/ParameterBinding/ParameterBinding.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -422,5 +422,25 @@
$result.Value[1] | Should Be 2
$result.Value[2] | Should Be 3
}

It "Binds properly when collections of type other than object[] are used on an advanced function" {
$list = [Collections.Generic.List[int]](1..3)
$result = Test-BindingFunction $list

$result.ArgumentCount | Should Be 3
$result.Value[0] | Should Be 1
$result.Value[1] | Should Be 2
$result.Value[2] | Should Be 3
}

It "Binds properly when collections of type other than object[] are used on a cmdlet" {
$list = [Collections.Generic.List[int]](1..3)
$result = Test-BindingCmdlet $list

$result.ArgumentCount | Should Be 3
$result.Value[0] | Should Be 1
$result.Value[1] | Should Be 2
$result.Value[2] | Should Be 3
}
}
}