【发布时间】:2016-04-19 15:28:04
【问题描述】:
我正在尝试创建一个返回网站绑定信息的函数。这是为了降低我的 dsc 资源文件的复杂性,该文件将有 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
【问题讨论】:
-
你能弄清楚如何预处理/计算你的绑定吗?我也有类似情况
-
似乎不可能。至少不使用当前版本的 ps/dsc
标签: powershell iis dsc