Skip to content
Merged
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 @@ -607,7 +607,7 @@ private void FilteredWriteObject(PSObject obj, List<PSNoteProperty> addedNotePro
{
if (obj != AutomationNull.Value)
{
SetPSCustomObject(obj);
SetPSCustomObject(obj, newPSObject: addedNoteProperties.Count > 0);
WriteObject(obj);
}

Expand Down Expand Up @@ -648,16 +648,22 @@ private void FilteredWriteObject(PSObject obj, List<PSNoteProperty> addedNotePro

if (isObjUnique)
{
SetPSCustomObject(obj);
SetPSCustomObject(obj, newPSObject: addedNoteProperties.Count > 0);
_uniques.Add(new UniquePSObjectHelper(obj, addedNoteProperties.Count));
}
}
}

private void SetPSCustomObject(PSObject psObj)
private void SetPSCustomObject(PSObject psObj, bool newPSObject)
{
if (psObj.ImmediateBaseObject is PSCustomObject)
psObj.TypeNames.Insert(0, "Selected." + InputObject.BaseObject.GetType().ToString());
{
var typeName = "Selected." + InputObject.BaseObject.GetType().ToString();
if (newPSObject || !psObj.TypeNames.Contains(typeName))
{
psObj.TypeNames.Insert(0, typeName);
}
}
}

private void ProcessObjectAndHandleErrors(PSObject pso)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1)
Add-TestDynamicType

Expand Down Expand Up @@ -349,4 +350,25 @@ Describe "Select-Object with Property = '*'" -Tags "CI" {
$p = Get-Process -Id $pid | Select-Object -Property Process* -ExcludeProperty ProcessorAffinity -ExpandProperty Modules
$p[0].psobject.Properties.Item("ProcessorAffinity") | Should -BeNullOrEmpty
}

It "Select-Object add 'Selected.*' type only once" {
$obj = [PSCustomObject]@{ Name = 1 }

$obj.psobject.TypeNames.Count | Should -Be 2
$obj.psobject.TypeNames | Should -Not -BeLike "Selected*"

$obj = $obj | Select-Object

$obj.psobject.TypeNames.Count | Should -Be 3
$obj.psobject.TypeNames[0] | Should -BeLike "Selected*"
$obj.psobject.TypeNames[1] | Should -Not -BeLike "Selected*"
$obj.psobject.TypeNames[2] | Should -Not -BeLike "Selected*"

$obj = $obj | Select-Object

$obj.psobject.TypeNames.Count | Should -Be 3
$obj.psobject.TypeNames[0] | Should -BeLike "Selected*"
$obj.psobject.TypeNames[1] | Should -Not -BeLike "Selected*"
$obj.psobject.TypeNames[2] | Should -Not -BeLike "Selected*"
}
}