diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs index b54873067ef..1c45fea699d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Select-Object.cs @@ -144,10 +144,11 @@ public int First private bool _firstOrLastSpecified; /// - /// Skips the specified number of items from top when used with First, from end when used with Last. + /// Skips the specified number of items from top when used with First, from end when used with Last or SkipLast. /// /// [Parameter(ParameterSetName = "DefaultParameter")] + [Parameter(ParameterSetName = "SkipLastParameter")] [ValidateRange(0, int.MaxValue)] public int Skip { get; set; } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 index 05885698392..04284453435 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Select-Object.Tests.ps1 @@ -231,6 +231,29 @@ Describe "Select-Object DRT basic functionality" -Tags "CI" { $results[1] | Should -Be 3 } + It "Select-Object with SkipLast should work" { + $results = "1", "2", "3" | Select-Object -SkipLast 1 + $results.Count | Should -Be 2 + $results[0] | Should -BeExactly "1" + $results[1] | Should -BeExactly "2" + } + + It "Select-Object with Skip and SkipLast should work" { + $results = "1", "2", "3" | Select-Object -Skip 1 -SkipLast 1 + $results.Count | Should -Be 1 + $results[0] | Should -BeExactly "2" + } + + It "Select-Object with Skip and SkipLast should work with Skip overlapping SkipLast" { + $results = "1", "2" | Select-Object -Skip 2 -SkipLast 1 + $results. Count | Should -Be 0 + } + + It "Select-Object with Skip and SkipLast should work with skiplast overlapping skip" { + $results = "1", "2" | Select-Object -Skip 1 -SkipLast 2 + $results. Count | Should -Be 0 + } + It "Select-Object with Index should work" { $results = "1", "2", "3" | Select-Object -Index 2 $results.Count | Should -Be 1