Created
January 8, 2025 20:40
-
-
Save steviecoaster/0f233b62c9c6a94a59ce6f688c1ca817 to your computer and use it in GitHub Desktop.
Fooling around with Write-Output in PowerShell
This file contains hidden or 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 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