PoshBytes: Copy, Paste, Automate!

In this episode of PoshBytes, we dive into the often-overlooked magic of PowerShell’s Get-Clipboard and Set-Clipboard cmdlets.

This post is a companion for the video embedded below. Scroll down to see the code from the video.

Watch the video on YouTube PoshBytes: Copy, Paste, Automate!

This post walks through simple, practical clipboard operations in PowerShell. Each example includes a short summary followed by the exact code used.

Example 1: Write text to the clipboard

Sends a string to the system clipboard so you can paste it anywhere.

'Hello from PowerShell!' | Set-Clipboard

Example 2: Read the clipboard

Retrieves whatever is currently on the clipboard and outputs it to the console.

Get-Clipboard

Example 3: Prepare sample CSV data (for the clipboard)

Provides a small CSV sample you can copy to the clipboard for parsing in later steps.

# Sample CSV
Name,Id,CPU
pwsh,1234,12.3
code,2345,08.7
explorer,3456,02.1

Example 4: Read the clipboard again

Reads whatever is on the clipboard at this point, useful after copying the CSV sample.

Get-Clipboard

Example 5: Parse CSV from the clipboard

Converts the clipboard’s CSV text into PowerShell objects so you can work with typed properties.

Get-Clipboard | ConvertFrom-Csv

Example 6: Convert CSV to JSON and send back to the clipboard

Takes the parsed CSV objects, converts them to JSON, and writes the JSON back to the clipboard.

Get-Clipboard | ConvertFrom-Csv | ConvertTo-Json | Set-Clipboard