Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a powershell script that is hashing the MAC address, then posting it into a file and a clipboard.

$hash = [System.BitConverter]::ToString($md5.ComputeHash($utf8.GetBytes($MAC)))
$hash | clip
$hash | Out-File $Env:USERPROFILE\Desktop\this.txt 

The issue I am having is that a carriage return is being exported to the clipboard. I don't want that.

Is there a way of stopping that happening?

Additional info - When I paste the text that is on the clipboard into a hex editor I see 0D0A

The clipboard function would be fine if I could just loose that some how? Thanks

share|improve this question
By the way, that's actually two characters: CR (carriage return) and LF (line feed). In other words, a Windows new line. – Bob Jul 19 '13 at 6:06

$Hash.TrimEnd() should clear any unicode whitespace at the end of the string.

share|improve this answer
That does not actually work. My theory is that clip itself inserts the newline. – Bob Jul 19 '13 at 6:04

Unfortunately, it looks like clip itself appends the newline. So, let's do it the .NET way!

Here's a function that takes stdin and puts it in the clipboard:

function Out-ClipboardText

        powershell -sta -noprofile -command "add-type -an; [System.Windows.Forms.Clipboard]::SetText('$text')"

Adapted from and

Use it like so:

$hash | Out-ClipboardText

It uses the .NET clipboard function to set the text. Unfortunately, it's also a little slow and complicated because it needs to start a new PowerShell process in STA mode, as required for Clipboard (source).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.