Skip to content

Instantly share code, notes, and snippets.

@SteveL-MSFT
Created October 5, 2022 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveL-MSFT/90989a08fd38134d39ac38d90fd7853f to your computer and use it in GitHub Desktop.
Save SteveL-MSFT/90989a08fd38134d39ac38d90fd7853f to your computer and use it in GitHub Desktop.
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