我试图创建一个返回网站bindinginfo的函数。这旨在降低我的dsc资源文件的复杂性,该文件将具有基于节点名称具有类似bindinginfo的20/30个网站。以下是我目前的情况,但我收到错误,而且我不确切知道如何解决这个问题。对此的任何帮助都将非常感激。
这就是我现在所拥有的:
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 :(得分:1)
不支持这种直接指定CimInstance的方法。您只能在配置块下创建MSFT_xWebBindingInformation的对象。以下是样本:
配置DscTest { Import-DscResource -ModuleName xWebAdministration;
Dim sipff As SystemInfoPropertiesForForm = listSystemInfoPropertiesForForm.Find(Function(f) f.ShowFieldPropertyTypeId = CInt(SystemInfoPropertyIds.ShowMilestone))
}
函数Get-TestBindingInformation { [输出类型([Microsoft.Management.Infrastructure.CimInstance []])] 参数( [System.Collections.Hashtable] $ node )
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
}
}
}
DscTest