CSVでプロパティ値を保存する
Export-Csvコマンドレットを使用すると、パイプラインから流れてきたオブジェクトのプロパティをCSVとして保存することができます。
実行例
PS U:\Scripts> Get-ChildItem
ディレクトリ: U:\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2010/09/08 19:35 OldScripts
d---- 2011/03/01 23:28 Security
d---- 2011/03/02 7:39 Setting
d---- 2011/02/08 20:21 VisualStudio
-a--- 2011/02/10 7:44 1926 CopyUpdatedSolutions.ps1
-a--- 2011/02/10 19:17 1373 CreateBackupFunc.ps1
-a--- 2010/09/09 7:06 343 Download.ps1
-a--- 2010/09/23 22:47 1290 Dump.ps1
-a--- 2011/02/08 20:00 888 GetBackupPathFunc.ps1
-a--- 2010/08/29 20:52 51 Pathes.txt
-a--- 2010/10/01 7:07 412 ReadText.ps1
-a--- 2010/10/14 20:51 1509 StartCpp.ps1
-a--- 2011/01/13 20:15 84 StartJava.ps1
-a--- 2010/10/01 7:07 441 WriteText.ps1
-a--- 2010/09/08 21:44 666 Zip.ps1
PS U:\Scripts> Get-ChildItem |
>> Export-Csv -Encoding default U:\Export.csv
>>
PS U:\Scripts>
出力結果
上記の実行結果として出力されたファイルをExcelで開きました。
出力されたCSVファイル
一見すると全然別のデータですが、PowerShellの画面に出力される情報以上にいろいろ出力されているために、そのように見えるだけです。実際には上の実行例で出力された情報+αが出力されています。