Skip to content

Instantly share code, notes, and snippets.

@gravejester
Created October 21, 2025 09:26
Show Gist options
  • Select an option

  • Save gravejester/99d3669b40815aa2286783d403a9be35 to your computer and use it in GitHub Desktop.

Select an option

Save gravejester/99d3669b40815aa2286783d403a9be35 to your computer and use it in GitHub Desktop.
pluralOf - add plural 's' only if array contains more than 1 element
# pluralOf - add plural 's' only if array contains more than 1 element
#
# example usage:
#
# Write-Host "Found $($computers.Count) computer$(pluralOf($computers))"
#
function pluralOf($inputObject) {
if ($inputObject -is [System.Array] -or $inputObject -is [System.Collections.ArrayList]) {
Write-Output "$($inputObject.Count -ne 1 ? 's' : '')"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment