オブジェクトのグループ化(group-object)
「group-object」は複数のオブジェクトに対して、プロパティ名でグルーピングを行います。
「group-object」
ファイルを拡張子でグルーピング
MSH C:\..\Orca> get-childitem | group-object {$_.extension} Count Name Group ----- ---- ----- 4 .cub {darice.cub, logo.cub, mergemod.cub, XPlogo.cub} 1 .chm {orca.chm} 1 .dat {orca.dat} 1 .exe {Orca.exe}
- 「ls | group {$_.extension}」と入力しても同じです。
- 「get-childitem」は長くて打つのが面倒ですよね。(^^;
プロパティの一覧を取得する
「group-object」でグルーピングする前に、
「オブジェクトにどうようなプロパティがあるのかを調べたい!」という場合は、
「get-member」を利用します。
「System.IO.FileInfo」のプロパティ一覧を取得
MSH C:\..\Orca>(get-childitem)[0] | get-member -membertype property TypeName: System.IO.FileInfo Name MemberType Definition ---- ---------- ---------- Attributes Property System.IO.FileAttributes Attributes {get;set;} CreationTime Property System.DateTime CreationTime {get;set;} CreationTimeUtc Property System.DateTime CreationTimeUtc {get;set;} Directory Property System.IO.DirectoryInfo Directory {get;} DirectoryName Property System.String DirectoryName {get;} Exists Property System.Boolean Exists {get;} Extension Property System.String Extension {get;} FullName Property System.String FullName {get;} IsReadOnly Property System.Boolean IsReadOnly {get;set;} LastAccessTime Property System.DateTime LastAccessTime {get;set;} LastAccessTimeUtc Property System.DateTime LastAccessTimeUtc {get;set;} LastWriteTime Property System.DateTime LastWriteTime {get;set;} LastWriteTimeUtc Property System.DateTime LastWriteTimeUtc {get;set;} Length Property System.Int64 Length {get;} Name Property System.String Name {get;}
- 「 (ls)[0] | gm -m property」と入力しても同じです。