Skip to content

Instantly share code, notes, and snippets.

@stormychel
Last active April 15, 2025 09:23
Show Gist options
  • Save stormychel/5aa7fc447172417424897e3348dc05bd to your computer and use it in GitHub Desktop.
Save stormychel/5aa7fc447172417424897e3348dc05bd to your computer and use it in GitHub Desktop.
PowerShell pbcopy function for Windows (mimics macOS pbcopy)
<#
pbcopy.ps1 β€” A PowerShell function to mimic macOS `pbcopy`
πŸ“Œ Usage:
"Hello world" | pbcopy
pbcopy # then type text, Ctrl+Z + Enter
πŸ“ Install:
- Save this file somewhere on disk, e.g. C:\Scripts\pbcopy.ps1
- Open your PowerShell profile: notepad $PROFILE
- Add this line: . "C:\Scripts\pbcopy.ps1"
- Reload profile: . $PROFILE
βœ… Now you can use `pbcopy` like on macOS.
#>
function pbcopy {
param([string]$input = $null)
if (-not $input) {
$input = Get-Content -Raw -Path "CON"
}
$input | Set-Clipboard
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment