オブジェクトのView定義(3)

オブジェクトのView定義(2) - PowerShell Memoの続きです。
今回は、オリジナルのカスタムViewを定義します。

プロセスの実行パスを表示するカスタムView

以下の「ProcessPath.mshxml」を作成します。
「ProcessPath」という名前のカスタムViewを定義しています。

ProcessPath.mshxml (D:\Doc\MSH)
<Configuration>
    <ViewDefinitions>
        <View>
            <Name>ProcessPath</Name>
            <ViewSelectedBy>
                <TypeName>System.Diagnostics.Process</TypeName>
            </ViewSelectedBy>
            <TableControl>
                <TableHeaders>
                    <TableColumnHeader>
                       <Label>プロセス名</Label>
                     </TableColumnHeader>
                     <TableColumnHeader>
                       <Label>パス</Label>
                     </TableColumnHeader>
                </TableHeaders>
                <TableRowEntries>
                    <TableRowEntry>
                        <TableColumnItems>
                     <TableColumnItem>
                       <PropertyName>Name</PropertyName>
                     </TableColumnItem>
                      <TableColumnItem>
                       <PropertyName>Path</PropertyName>
                     </TableColumnItem>
                        </TableColumnItems>
                    </TableRowEntry>
                 </TableRowEntries>
            </TableControl>
        </View>        
    </ViewDefinitions>
</Configuration>

カスタムViewを読み込む(Update-FormatData)

以下のコマンドで「ProcessPath.mshxml」を読み込ませます。

update-formatdata D:\Doc\MSH\ProcessPath.mshxml

読み込んだカスタムViewを使用するには、「Format-Table」Cmdletを利用します。

get-process | format-table -view ProcessPath

出力結果
プロセス名              パス
----------              ----
B2                      D:\Apps\Net\Becky\B2.exe
BsCLiP                  D:\Apps\DVD\B'sCLiP\Win2K\BSCLIP.exe
BSKP-U201 Skype Phone   C:\Program Files\BUFFALO USB Phone\BSKP-U201\B...
(中略)

ProcessPath.mshxmlで定義したViewを用いて、プロセスの実行パスが表示されました。


ちなみに、「update-formatdata」で「PrependPath」オプションを付けると、
標準のmshxmlよりも優先させることができます。

MSH C:\> update-formatdata -PrependPath D:\Doc\MSH\ProcessPath.mshxml
MSH C:\> get-process

プロセス名              パス
----------              ----
B2                      D:\Apps\Net\Becky\B2.exe
BsCLiP                  D:\Apps\DVD\B'sCLiP\Win2K\BSCLIP.exe
BSKP-U201 Skype Phone   C:\Program Files\BUFFALO USB Phone\BSKP-U201\B...
(中略)

次回は、カスタムViewを簡単に作成するツールを紹介します。