PowerTip: Copy Information to the Clipboard with PowerShell

PowerTip: Copy Information to the Clipboard with PowerShell

  • Comments 5
  • Likes

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;

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • A more interesting tip would be about how to get text from the clipboard in PowerShell.

  • 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.

  • It can be done without STA also. http://techibee.com/powershell/powershell-script-to-copy-powershell-command-output-to-clipboard/1316

  • 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() }