1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Set-ClipBoardという取り回しのいいコマンド

Posted at

PowerShellで出力する方法

いくつか方法があるし、いくらでも方法があるけれど、主たるところは以下の2種類か。

  • 標準出力でそのままコンソール上に出力する
  • Out-File でファイルを出力する

最近、もうひとついい方法

  • Set-ClipBoard でクリップボードに直接出力する

クリップボードに出力するメリット

貼り付けでテキストエディタに出力できるので、Out-Fileとそれほど取り回しは変わらない。
Tabで区切って、Excelやスプレッドシートに貼り付けるとそのままファイル化できる、というメリットもある。
もちろん、そのままメールやチャットソフトに貼り付ける、などもできるだろう。

Set-ClipBoardの例文

例えば、以下の構文でカレントフォルダにあるファイルのフルパスと最終更新日時を取得することができる。

$tmp = Get-ChildItem -Path . -Recurse | ? { $_.LastAccessTime -gt "2020/04/01" } | ft -autosize -property FullName, LastWriteTime | Out-String -Width 4000
$tmp | Set-ClipBoard

以下のコマンドだとCSV化することができる

$tmp = Get-ChildItem -Path . -Recurse | ? { $_.LastAccessTime -gt "2020/04/01" } | select Fullname,  LastWriteTime | ConvertTo-Csv
$tmp | Set-ClipBoard

クリップボードなのでメモリに出力されるし、そのまま色々なメディアに持っていくことができるので、一度テキスト出力するよりも早く取り回しがいい。

活用しがいのあるコマンドだ。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?