PowerTip: Copy Information to the Clipboard with PowerShell

Summary: Learn how to easily copy information to the clipboard by using Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to copy WMI information to the Windows Clipboard
          so I can use it in another application?

Hey, Scripting Guy! Answer Use the external clip.exe utility to copy Windows PowerShell pipeline output to your Windows clipboard!
          For example, to get a list of WMI classes in the root\cimv2 namespace on your computer and then
          copy the list to the Windows clipboard, run the following command:

(Get-CimClass | Sort-Object –Property CimClassName).CimClassName | clip.exe;

Comments (5)

  1. Anonymous says:

    First I was using this function to save the clipboard content in an array: Add-Type -AssemblyName PresentationCore function PasteFromClipboard { [System.Windows.Clipboard]::GetText() -split "`n" } But when I had to use samAccountNames from the clipboard
    I saw that there were whitespaces at the end of each string. So I extended the function: { [System.Windows.Clipboard]::GetText() -split "`n" | foreach { $_.trim() }

  2. Anonymous says:

    Pasting from clipboard to powershell: $paste = PowerShell -NoProfile -STA -Command { add-type -assembly PresentationCore; Windows.Clipboard]::GetText() } Now just call $paste to paste content from your clipboard.

  3. OldFart says:

    A more interesting tip would be about how to get text from the clipboard in PowerShell.

  4. Fadi says:

    I have only just started using powershell at version 4 which came out after your tip, so maybe the version you were using is different. You can only run exe by puting a . befire them. I only got it to pipe when I used "| .clip.exe" . You might want to
    make a not of that in your totorial. Thanks!