進化を続けるPowerShell DSCで利用できるリソースを確認する方法

こちらの記事でDSCでAzure上の仮想マシンの自動構築のやり方を書きました。

しかし、DSCさえあれば100%何でもできると言う訳ではありません。DSCで何かできるのかはDSCのリソースというもので表現されています。デフォルトではこちらの12種類のリソースがDSCに定義されています。

DSCは日々進化を続けていて、リソースの種類も増えてきています。記事を書いている現時点でWave4まで出てきています。

Wave1 LINK
Wave2 LINK
Wave3 LINK
Wave4 LINK
Wave5 LINK
Wave6 LINK
All Modules LINK

 
 

つまり、サーバ毎にどのDSCリソースが使えるかが異なる可能性があるということです。利用できるDSCリソースを確認するには「Get-DSCResource」コマンドが利用できます。手元のPCでGet-DSCResourceを実行した結果が以下の通りです。

PS > Get-DscResource

ImplementedAs   Name                      Module                         Properties
-------------   ----                      ------                         ----------
Binary          File                                                     {DestinationPath, Attri...
PowerShell      Archive                   PSDesiredStateConfiguration    {Destination, Path, Che...
PowerShell      Environment               PSDesiredStateConfiguration    {Name, DependsOn, Ensur...
PowerShell      Group                     PSDesiredStateConfiguration    {GroupName, Credential,...
Binary          Log                       PSDesiredStateConfiguration    {Message, DependsOn}
PowerShell      Package                   PSDesiredStateConfiguration    {Name, Path, ProductId,...
PowerShell      Registry                  PSDesiredStateConfiguration    {Key, ValueName, Depend...
PowerShell      Script                    PSDesiredStateConfiguration    {GetScript, SetScript, ...
PowerShell      Service                   PSDesiredStateConfiguration    {Name, BuiltInAccount, ...
PowerShell      User                      PSDesiredStateConfiguration    {UserName, DependsOn, D...
PowerShell      WindowsFeature            PSDesiredStateConfiguration    {Name, Credential, Depe...
PowerShell      WindowsProcess            PSDesiredStateConfiguration    {Arguments, Path, Crede...


オブジェクトを展開しないと、設定できるPropertyがわからないと思いスクリプト組みました。

$resources = Get-DscResource
$list = New-Object System.Collections.Generic.List[System.Object]
foreach($r in $resources){
    foreach($p in $r.Properties){       
        if($p.Values.Count -eq 0){
            $obj = New-Object psobject |
                    Add-Member -Name ResourceName -Type NoteProperty -Value $r.Name -PassThru |
                    Add-Member -Name PropertyName -Type NoteProperty -Value $p.Name -PassThru | 
                    Add-Member -Name PropertyType -Type NoteProperty -Value $p.PropertyType -PassThru |    
                    Add-Member -Name IsMandatory  -Type NoteProperty -Value $p.IsMandatory -PassThru |   
                    Add-Member -Name Value  -Type NoteProperty -Value $null -PassThru             
            $list.Add($obj)        
        }
        else{
            foreach($v in $p.Values){
                $obj = New-Object psobject |
                        Add-Member -Name ResourceName -Type NoteProperty -Value $r.Name -PassThru |
                        Add-Member -Name PropertyName -Type NoteProperty -Value $p.Name -PassThru | 
                        Add-Member -Name PropertyType -Type NoteProperty -Value $p.PropertyType -PassThru |    
                        Add-Member -Name IsMandatory  -Type NoteProperty -Value $p.IsMandatory -PassThru |   
                        Add-Member -Name Value  -Type NoteProperty -Value $v -PassThru             
                $list.Add($obj)    
            }
        }
    }
}

$list | Out-GridView




最後にOut-GridViewに出力しているので、以下のような画面が表示されると思います。テキストやCSVに出力しても便利だと思います。




これで自分の利用したいリソースが使えるかを確認できると思います。