Created
October 5, 2022 22:17
-
-
Save SteveL-MSFT/90989a08fd38134d39ac38d90fd7853f to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Management.Automation; | |
using System.Text; | |
namespace ClipboardReverse | |
{ | |
[Cmdlet(VerbsCommon.Get,"ClipboardReverse")] | |
[OutputType(typeof(string))] | |
public class ClipboardReverse : PSCmdlet | |
{ | |
protected override void EndProcessing() | |
{ | |
var ps = PowerShell.Create(); | |
ps.AddCommand("Get-Clipboard").AddParameter("Raw"); | |
var output = ps.Invoke<string>(); | |
if (ps.HadErrors) | |
{ | |
WriteError(new ErrorRecord(ps.Streams.Error[0].Exception, "Get-Clipboard Error", ErrorCategory.NotSpecified, null)); | |
} | |
else | |
{ | |
var sb = new StringBuilder(); | |
foreach (var text in output) | |
{ | |
sb.Append(text); | |
} | |
var reversed = sb.ToString().ToCharArray(); | |
Array.Reverse(reversed); | |
WriteObject(new string(reversed)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment