2017-06-22 10 views
3

と非デフォルトのプロパティの間、私はPowerShellを練習していますし、次のように私が割り当てられている質問です:Specifiyingが選択-オブジェクト

は、プロパティを返す、CPU使用率がゼロより大きいプロセスを取得するためにパイプラインを書きます既定のビューには表示されず、CPUの降順で結果を並べ替えます。

現在、私はSelect-Objectコマンドレットで実行できると仮定している以外のすべての既定のプロパティの要件を除いて完了しています。

私がこれまで持っているコード:

Get-Process | Where-Object {$_.CPU -gt 0 } | Select-Object -Property * | sort -Descending 

私はアスタリスクがすべてのプロパティを選択するためのあだ名である知っているが、プロパティがデフォルトのビューである場合、私はブールチェックを設定する方法がわかりませんか否か。誰か助けてくれますか?

+1

言葉の解釈の問題かもしれません。既定のビューに表示されているプロパティを返すと、表示されていない余分なプロパティが*必要なものであると解釈できます。 'Get-Process | Get-Member'を呼び出して、既定値としてフラグを立てるプロパティについて何かがあるかどうかを確認します。 – mjsqu

答えて

3

選択-Object内の-ExcludePropertyオプションを見てみましょう。

Get-Process | ` 
Where-Object {$_.CPU -gt 0 } | ` 
Select-Object -Property * -ExcludeProperty $(Get-Process)[0].PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames | ` 
sort -Descending | format-table 

$(Get-Process)[0].PSStandardMembers.DefaultDisplayPropertySet).ReferencedPropertyNames 

Get-Process出力の最初の返された値のためのデフォルトのリストです。すべてを打ち破る:

# First process 
$fp = $(Get-Process)[0] 
# Standard Members 
$PSS = $fp.PSStandardMembers 
# Default Display Property Set 
$DDPS = $PSS.DefaultDisplayPropertySet 
# Names of those properties in a list, that you can pass to -ExcludeProperty 
$Excl = $DDPS.ReferencedPropertyNames 
$Excl 

# Command using variables 
Get-Process | ` 
Where-Object {$_.CPU -gt 0 } | ` 
Select-Object -Property * -ExcludeProperty $Excl | ` 
sort -Descending | format-table 
関連する問題