Clearing Clipboard

Hi everyone:

I am looking how to solve this issue. I need to clean or clear the clipboard.

I need to do this in a windows server 2008 r2.

I have found some instructions like:

  • echo off | clip
  • (but it only works in CMD or BAT)
 
  • Add-Type -AssemblyName System.Windows.Forms
    [System.Windows.Forms.Clipboard]::Clear()
  • But it only works in powershell ISE and Windows 10 powershell
Any suggestion, please?

 

 

What version of powershell do you need this to work on? How about:

Set-Clipboard " "

 

As Mike suggests, PS version is key if you want to use Set-Clipboard as it was introduced in a later version (5.0?). Although I would suggest using $null rather than an empty string or one with a space in it.

Set-Clipboard $null

If the cmdlet isn’t available, you should be able to pipe to clip.exe in PowerShell without any problem if the cmdlet is not available to you. The example you gave isn’t working because in PowerShell echo is an alias for Write-Output.

$null | clip.exe

 

Hi again.

Right, very important.

On this Windows server 2008 r2 is powershell 2.0

You should still have clip.exe installed so just use it like Matt said. $null | clip.exe