#author("2019-08-13T21:09:29+09:00","default:ryuichi","ryuichi")
#author("2019-08-13T21:10:04+09:00","default:ryuichi","ryuichi")
* Select-Objectで特定のプロパティを文字列で取得 [#p7e2abde]
*** dirで取得するのはFileInfoオブジェクト [#pe7528c6]
PS> dir *.txt | gm
TypeName: System.IO.FileInfo
*** FileInfoオブジェクトをパイプしてselectするとSelected.System.IO.FileInfoオブジェクト [#cd022213]
PS> dir *.txt | select FullName
FullName
--------
C:\tmp\1.txt
C:\tmp\2.txt
C:\tmp\3.txt
PS> dir *.txt | select FullName | ConvertTo-Json
[
{
"FullName": "C:\\tmp\\1.txt"
},
{
"FullName": "C:\\tmp\\2.txt"
},
{
"FullName": "C:\\tmp\\3.txt"
}
]
PS> dir *.txt | select FullName | gm
TypeName: Selected.System.IO.FileInfo
*** オブジェクトではなく文字列で取得するには-ExpandPropertyを使う [#o129e383]
PS> dir *.txt | select -ExpandProperty FullName | ConvertTo-Json
[
"C:\\tmp\\1.txt",
"C:\\tmp\\2.txt",
"C:\\tmp\\3.txt"
]
PS> dir *.txt | select -ExpandProperty FullName | gm
TypeName: System.String