Skip to content

Instantly share code, notes, and snippets.

@NathanTheGr8
Last active August 31, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanTheGr8/ba2c42ff405d6f9f5e3e8e67e306e2d0 to your computer and use it in GitHub Desktop.
Save NathanTheGr8/ba2c42ff405d6f9f5e3e8e67e306e2d0 to your computer and use it in GitHub Desktop.
function Select-Nth {
<#
.SYNOPSIS
Seletc the Nth element in an array
.DESCRIPTION
Selects the Nth Element in an array. Like the 3rd, 5th, 98th, etc
.PARAMETER N
The Nth element you want to select
.EXAMPLE
Select-Nth 6
Selects the 6th element of an array
.LINKS
https://stackoverflow.com/questions/31831470/select-second-or-third-object-element
.NOTES
Discussion https://www.reddit.com/r/PowerShell/comments/6x8cja/selectnth_element/
#>
param(
[ValidateRange(1,[int]::MaxValue)]
[int]$N
)
$Input | Select-Object -Skip ($N - 1) | Select-Object -First 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment