get-command | where-object { $_.commandtype -eq "cmdlet" } | sort-object -property name | select-object -property name | where-object { $_.name -match "^get" } | out-file "getcommands.txt"
$content = get-content "getcommands.txt"
$content | Foreach-Object { $_.TrimEnd() } | where { $_ -match "\w" } | Out-File "getcommands.txt" -encoding Ascii
compare-object -referenceobject $(Get-Content "oldcommands.txt") -differenceobject $(Get-Content "getcommands.txt") -includeequal
このコードは、"get" で始まるすべてのコマンドレットを取得し、それらをテキスト ファイル内のリストと比較します。また、余分なリターンと空白を削除するため、比較は実際に機能します。
すべてが機能しますが、読むのはかなり難しいです。PowerShell スクリプトの書き方を学んでいるところなので、より洗練されたコードで同じタスクを達成する方法がわかりません。
すべてのパイプなしでこれを行う方法があるに違いありません。また、コードの最初の行からテキスト ファイルに出力するための出力を、大量の余分なスペースと改行なしで取得することもできませんでした。