Last active
August 31, 2017 19:14
-
-
Save NathanTheGr8/ba2c42ff405d6f9f5e3e8e67e306e2d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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