ConvertTo-Csv

TYPEの削除 -NoTypeInformationオプション

 PS> dir *.txt | select FullName, FileSize, LastWriteTime | ConvertTo-Csv
 #TYPE Selected.System.IO.FileInfo       <= *** この行が不要な場合 ***
 "FullName","FileSize","LastWriteTime"
 "C:\tmp\1.txt"," 786 B ","2018/05/15 3:40:31"
 "C:\tmp\2.txt"," 786 B ","2018/05/15 3:40:24"

 PS> dir *.txt | select FullName, FileSize, LastWriteTime | ConvertTo-Csv -NoTypeInformation
 "FullName","FileSize","LastWriteTime"
 "C:\tmp\1.txt"," 786 B ","2018/05/15 3:40:31"
 "C:\tmp\2.txt"," 786 B ","2018/05/15 3:40:24"

デリミタの指定 -Delimiter

 dir * | select FullName, FileSize, LastWriteTime | ConvertTo-Csv -Delimiter "`t"

ここではタブ区切りを指定。

最初の行のヘッダーなど、邪魔な行があるのを消す select -Skip

 PS> dir *.txt | select FullName, FileSize, LastWriteTime | ConvertTo-Csv -NoTypeInformation
 "FullName","FileSize","LastWriteTime"                <= *** この行が邪魔 ***
 "C:\tmp\1.txt"," 786 B ","2018/05/15 3:40:31"
 "C:\tmp\2.txt"," 786 B ","2018/05/15 3:40:24"

 PS> dir *.txt | select FullName, FileSize, LastWriteTime | ConvertTo-Csv -NoTypeInformation | select -Skip 1
 "C:\tmp\1.txt"," 786 B ","2018/05/15 3:40:31"
 "C:\tmp\2.txt"," 786 B ","2018/05/15 3:40:24"

参考

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/convertto-csv


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2018-05-15 (火) 06:01:57