PowerShell でテキストをクリップボードへコピー、クリップボードからペーストします。
Clipboardクラスを使用しますので、STA(Single Thread Apartment)モードでPowerShellを起動する必要があります。
powershell.exe -sta
クリップボードへコピー
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Clipboard]::SetDataObject("この文字をコピー")
クリップボードからペースト
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");
$data = [System.Windows.Forms.Clipboard]::GetDataObject()
if($data.GetDataPresent([System.Windows.Forms.DataFormats]::Text)) {
Write-Output $Data.GetData([System.Windows.Forms.DataFormats]::Text);
}