インストール済みのWindows Serverの役割と機能を一覧するPowerShellコマンド

インストール済みのWindows Severの役割と機能はGet-WindowsFeatureで簡単に一覧できます。いくつかバリエーションを書いてみます。


以下のコマンドではInstalled(インストール済み)の役割と機能を一覧しています。

PS> Get-WindowsFeature | ?{$_.InstallState -eq [Microsoft.Windows.ServerManager.Commands.InstallState]::Installed}

Get-WindowsFeatureのデフォルト出力はツリー状になっています。

Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] Web サーバー (IIS)                                  Web-Server                     Installed
    [X] Web サーバー                                    Web-WebServer                  Installed
        [X] HTTP 共通機能                               Web-Common-Http                Installed
            [X] HTTP エラー                             Web-Http-Errors                Installed
            [X] ディレクトリの参照                      Web-Dir-Browsing               Installed
            [X] 既定のドキュメント                      Web-Default-Doc                Installed
            [X] 静的なコンテンツ                        Web-Static-Content             Installed
        [X] セキュリティ                                Web-Security                   Installed
            [X] 要求フィルター                          Web-Filtering                  Installed
            [X] Windows 認証                            Web-Windows-Auth               Installed
            [X] ダイジェスト認証                        Web-Digest-Auth                Installed
        [X] パフォーマンス                              Web-Performance                Installed
            [X] 静的なコンテンツの圧縮                  Web-Stat-Compression           Installed
        [X] 状態と診断                                  Web-Health                     Installed
#....省略

 


ツリー表示でなく名前のリストだけ取りたければ。

PS> Get-WindowsFeature | ?{$_.InstallState -eq [Microsoft.Windows.ServerManager.Commands.InstallState]::Installed}  | select DisplayName
DisplayName
-----------
Web サーバー (IIS)
Web サーバー
HTTP 共通機能
HTTP エラー
ディレクトリの参照
既定のドキュメント
静的なコンテンツ
セキュリティ
要求フィルター
Windows 認証
#....省略


更にツリーの最下層だけ取りたければ。SubFeaturesが0のものをリストすればよいので。

PS> Get-WindowsFeature | ?{$_.InstallState -eq [Microsoft.Windows.ServerManager.Commands.InstallState]::Installed -and $_.SubFeatures.Count -eq 0} | select DisplayName

 
 

例えばインストール済みの機能と役割を説明付きでCSVに出力したければ。

PS> Get-WindowsFeature | ?{$_.InstallState -eq [Microsoft.Windows.ServerManager.Commands.InstallState]::Installed -and $_.SubFeatures.Count -eq 0}  | select DisplayName,Description | Export-Csv -Encoding UTF8 C:\features.csv

自分向けメモ用に。