When you press Ctrl+C in Windows 11, the operating system saves your data to the graphical clipboard. While you can easily paste this data into a Word document using Ctrl+V, manipulating clipboard data during an automated administrative task is much harder. If you need to instantly strip rich formatting from copied text or dump the contents of your clipboard directly into a log file without opening a text editor, PowerShell provides the perfect tool: the Get-Clipboard cmdlet.
What Does Get-Clipboard Do?
The Get-Clipboard command acts as a bridge between the Windows graphical user interface and the command-line environment. It reaches into the system memory, grabs whatever string of text you most recently copied, and pulls it straight into your PowerShell console. From there, you can manipulate it like any standard string variable.
Basic Clipboard Retrieval
Using the command requires zero configuration.
- Highlight a sentence on a web page and press Ctrl+C to copy it.
- Open the Windows 11 Start Menu.
- Type PowerShell and press Enter.
- In the console window, type the following command:
Get-Clipboard
Press Enter. The text you just copied will instantly print to the console screen. Crucially, the command automatically strips away any HTML formatting, fonts, or colours, outputting only the raw, plain text string.
Exporting Clipboard Data to a File
The most practical application of this command is rapidly saving copied data without opening Notepad. By using the standard PowerShell redirection operator (>), you can dump the clipboard contents directly into a new file on your hard drive.
For example, if you just copied an important error code from a pop-up window and want to save it to your desktop, run:
Get-Clipboard > "$env:USERPROFILE\Desktop\error_log.txt"
If you want to append new copied text to an existing file without overwriting the older data, use the double redirection operator (>>):
Get-Clipboard >> "$env:USERPROFILE\Desktop\error_log.txt"
Retrieving Multiple Lines of Text
If you copy a massive block of text containing multiple paragraphs, the standard Get-Clipboard command will retrieve the entire block as a single, continuous string variable. This makes it difficult to search or filter the text.
To force PowerShell to treat every line break as a separate object, you must append the -Raw flag and set it to false (or in older versions of PowerShell, simply omit the flag to let it default to returning an array of strings depending on your environment).
To specifically search your clipboard for a keyword, you can pipe the output directly into the Select-String cmdlet:
Get-Clipboard | Select-String -Pattern "Error"
This command will scan your massive copied text block and output only the specific sentences that contain the word “Error”.
Clearing the Clipboard
If you just copied a highly sensitive password and want to ensure it is immediately wiped from system memory before you walk away from your desk, PowerShell includes a companion cmdlet specifically for this purpose.
While Get-Clipboard retrieves data, you can use Set-Clipboard to overwrite it. To instantly blank the clipboard entirely, run:
Set-Clipboard -Value $null
If you run Get-Clipboard immediately after, it will return absolutely nothing, proving your sensitive data has been destroyed.