在基于类的DSC资源中使用[array]

时间:2016-11-13 10:27:02

标签: class powershell dsc

我一直在创建一些基于类的自定义DSC资源,我遇到了以下问题:

每当我尝试使用数组作为我的资源的输入时,我都会收到错误。

例如

RealmResults<FestivalEntity> results = realm.where(FestivalEntity.class)
     .equalTo("performances.favorite", true)
     .findAll(); 

当我尝试使用我的资源创建MOF文件时会导致以下错误:

  

Write-NodeMOFFile:节点&#39; nodename&#39;的无效MOF定义:   Exceptioncalling&#34; ValidateInstanceText&#34;用&#34; 1&#34;参数(一个或多个):
  &#34;转换属性&#39;产品&#39;值类型&#39; STRING []&#39;输入&#39; INSTANCE&#39;失败。

DscProperty(Mandatory)] [array]$Products 的输入对象将是(例如):

$Products

老实说,我不知道为什么$Products = @("Windows server 2012", "Windows SQL Server", "Windows 8.1") 函数会尝试转换数组(它不应该转换,对吧?),即使它需要转换 - 为什么它会从{{转换一个数组? 1}}到Write-NodeMOFFile

任何人都知道为什么会这样? 我让它工作的唯一方法是从我的字符串数组中创建一个长字符串,然后在资源中分隔它们。

1 个答案:

答案 0 :(得分:1)

声明这样的数组:

[string[]]$product="ddd","dq","dqq"