Introduction
PowerShell is known for its incredible versatility, but some of its best features remain hidden from everyday users. One such obscure yet highly useful trick is Clipboard Tunneling—a technique that enables data transfer between local and remote machines using the clipboard.
This method eliminates the need for file transfers, network shares, or manual copy-pasting, making it a game-changer for sysadmins, developers, and security professionals. Let’s explore how it works and why it’s a must-know technique.
What is Clipboard Tunneling in PowerShell?
Clipboard Tunneling uses two simple PowerShell cmdlets:
Set-Clipboard→ Copies data into the clipboard.Get-Clipboard→ Retrieves data from the clipboard.
By leveraging these commands within PowerShell remoting (Invoke-Command), we can transfer data across machines without the need for intermediate files.
Real-World Use Cases
Transfer Data from a Remote Machine to Local Clipboard
Want to grab a process list from a remote machine and paste it locally? Easy.
Invoke-Command -ComputerName RemotePC -ScriptBlock {
Get-Process | Out-String | Set-Clipboard
}
PowerShellWhat Happens?
- PowerShell runs
Get-Processon RemotePC. - The output is converted into a string.
- It is stored in the remote clipboard.
- If using RDP, the clipboard syncs automatically to your local machine.
Extract JSON from Clipboard & Convert It
Instead of pasting JSON into a file and processing it, retrieve it directly from the clipboard and convert it instantly.
$Data = Get-Clipboard | ConvertFrom-Json
$Data | Format-Table -AutoSize
PowerShellWhy? This method avoids unnecessary files and speeds up data parsing.
Save Clipboard Contents to a File
Quickly store whatever is in the clipboard to a file.
Get-Clipboard | Out-File C:\Temp\ClipboardContent.txt
PowerShellWhy? Perfect for capturing output from scripts, logs, or debugging.
4️⃣ Execute a Script from Clipboard
Ever copied a script snippet and wanted to execute it directly? PowerShell allows you to run clipboard contents as a script instantly.
Invoke-Expression (Get-Clipboard)
PowerShell⚠ Security Tip: Always verify clipboard contents before running commands.
Bonus: Wipe Clipboard for Security
After handling sensitive data, clear the clipboard with:
Set-Clipboard -Value $null
PowerShellConclusion
Clipboard Tunneling in PowerShell is an underrated yet incredibly effective technique for transferring and manipulating data across systems. Whether you’re a sysadmin, developer, or security analyst, mastering Set-Clipboard and Get-Clipboard will streamline your workflow.
Have you used Clipboard Tunneling before? Share your experiences in the comments below!
References
- Microsoft Docs:
Set-Clipboard - Microsoft Docs:
Get-Clipboard - Microsoft Docs:
Invoke-Command
