Clearing Clipboard

Welcome Forums General PowerShell Q&A Clearing Clipboard

Viewing 4 reply threads
  • Author
    Posts
    • #272641
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      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?

       

       

    • #272656
      Participant
      Topics: 5
      Replies: 177
      Points: 686
      Helping Hand
      Rank: Major Contributor

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

       

    • #272686
      Participant
      Topics: 2
      Replies: 382
      Points: 523
      Helping Hand
      Rank: Major Contributor

      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.

      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.

       

    • #273487
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      Hi again.

      Right, very important.

      On this Windows server 2008 r2 is powershell 2.0

    • #273541
      Participant
      Topics: 5
      Replies: 177
      Points: 686
      Helping Hand
      Rank: Major Contributor

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

Viewing 4 reply threads
  • You must be logged in to reply to this topic.