# encoding: ascii
# api: powershell
# title: Skip-Object
# description: Skip -every 3rd, or -upto 3 at a time, or the -first 3, or the -last 3 or any combination of the above …
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Skip-Object
# x-poshcode-id: 1778
# x-archived: 2010-04-17T07:56:02
#
#
function Skip-Object {
param(
[int]$First = 0, [int]$Last = 0, [int]$Every = 0, [int]$UpTo = 0,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$InputObject
)
begin {
if($Last) {
$Queue = new-object System.Collections.Queue $Last
}
$e = $every; $UpTo++; $u = 0
}
process {
$InputObject | where { --$First -lt 0 } |
foreach {
if($Last) {
$Queue.EnQueue($_)
if($Queue.Count -gt $Last) { $Queue.DeQueue() }
} else { $_ }
} |
foreach {
if(!$UpTo) { $_ } elseif( --$u -le 0) { $_; $U = $UpTo }
} |
foreach {
if($every -and (--$e -le 0)) { $e = $every } else { $_ }
}
}
}