2016-04-19 14 views
0

Webサイトのbindinginfoを返す関数を作成しようとしています。これは、ノード名に基づいて同様のbindinginfoを持つ20/30のWebサイトを持つdscリソースファイルの複雑さを軽減することを目的としています。以下は私が現時点で持っているものですが、私はエラーが発生しており、正確にどのように並べ替えるべきかはわかりません。これに関する助けは本当に感謝しています。WebサイトのDSC BindingInfoを返す関数を作成します。

これは私が現時点で持っているものです。

configuration DscTest 
{ 
    Import-DscResource -ModuleName xWebAdministration; 

    Node localhost 
    { 
     xWebsite TestWebSite 
     { 
      Ensure = "Present" 
      Name = "TestWebSite" 
      PhysicalPath = "C:\inetpub\test" 
      BindingInfo = (Get-TestBindingInformation $Node) 
     } 
    } 
} 

function Get-TestBindingInformation 
{ 
    [OutputType([Microsoft.Management.Infrastructure.CimInstance[]])] 
    param(
     [System.Collections.Hashtable] $node 
    ) 

    return @(
     New-CimInstance -ClassName MSFT_xWebBindingInformation -Namespace root/microsoft/Windows/DesiredStateConfiguration -Property @{ 
      Port     = 80 
      Protocol    = "HTTP" 
      HostName    = "test1" 
     } -ClientOnly 

     New-CimInstance -ClassName MSFT_xWebBindingInformation -Namespace root/microsoft/Windows/DesiredStateConfiguration -Property @{ 
      Port     = 80 
      Protocol    = "HTTP" 
      HostName    = "test2" 
     } -ClientOnly 
    ) 
} 

DscTest 

そして、これは私が取得エラーです:

Write-NodeMOFFile : Invalid MOF definition for node 'localhost': Exception calling "ValidateInstanceText" with "1" argument(s): 
"Convert property 'BindingInfo' value from type 'STRING[]' to type 'INSTANCE[]' failed           
At line:22, char:2                            
Buffer:                               
onName = "DscTest";                            
};^                                
insta                               
"                                
At C:\windows\system32\windowspowershell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2193 char:21 
+ ...    Write-NodeMOFFile $Name $mofNode $Script:NodeInstanceAlia ...             
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~              
    + CategoryInfo   : InvalidOperation: (:) [Write-Error], InvalidOperationException          
    + FullyQualifiedErrorId : InvalidMOFDefinition,Write-NodeMOFFile                
+0

バインディングの事前処理/計算方法を把握できましたか?私は似たような状況にあります – webbexpert

+0

それは可能ではないようです。 ps/dscの現在のバージョンではない – gigi

答えて

1

直接サポートされていませんCimInstanceを指定するこの方法。 MSFT_xWebBindingInformationのオブジェクトのみを作成することができ、設定ブロックの下にもオブジェクトを作成することができます。ここにサンプルがあります。

構成DscTest { Import-DscResource -ModuleName xWebAdministration;

Node localhost 
{ 
    $bindingInfo = @() 
    Get-TestBindingInformation $Node| foreach { 
     $bindingInfo += MSFT_xWebBindingInformation {Port = $_.Port; Protocol = $_.Protocol; HostName = $_.HostName} 
    } 
    xWebsite TestWebSite 
    { 
     Ensure = "Present" 
     Name = "TestWebSite" 
     PhysicalPath = "C:\inetpub\test" 
     BindingInfo = $bindingInfo 
    } 
} 

}

機能は、Get-TestBindingInformation {[OUTPUTTYPE([Microsoft.Management.Infrastructure.CimInstance []])] PARAM( [System.Collections.Hashtable] $ノード )

return @(
    New-CimInstance -ClassName MSFT_xWebBindingInformation -Namespace root/microsoft/Windows/DesiredStateConfiguration -Property @{ 
     Port     = 80 
     Protocol    = "HTTP" 
     HostName    = "test1" 
    } -ClientOnly 

    New-CimInstance -ClassName MSFT_xWebBindingInformation -Namespace root/microsoft/Windows/DesiredStateConfiguration -Property @{ 
     Port     = 80 
     Protocol    = "HTTP" 
     HostName    = "test2" 
    } -ClientOnly 
) 

}

DscTest

関連する問題