Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Created January 8, 2025 20:40
Show Gist options
  • Save steviecoaster/0f233b62c9c6a94a59ce6f688c1ca817 to your computer and use it in GitHub Desktop.
Save steviecoaster/0f233b62c9c6a94a59ce6f688c1ca817 to your computer and use it in GitHub Desktop.
Fooling around with Write-Output in PowerShell
function Write-ReverseOuput {
[Alias('Write-Output')]
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]
$InputObject
)
end {
#Turn our string input into an array of chars
$charArray = $InputObject.ToCharArray()
#the reverse method on the [Array] class reverse the characters in place.
#No need to store them in another variable, and it has no output to squash!
[Array]::Reverse($charArray)
#We then join our reversed char array back into its original string representation, and output it...this time only backwards :)
-join($charArray)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment