Auzure Automation DSC-带有字符串数组输入参数的编译错误 [英] Auzure Automation DSC - Compilation error with string array input parameter

查看:83
本文介绍了Auzure Automation DSC-带有字符串数组输入参数的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在尝试使用默认的复合资源"WindowsFeatureSet"之一在AA DSC中创建一个非常简单的配置

I'm trying to create a really simple configuration in AA DSC, using one of the default composite resources 'WindowsFeatureSet'

在门户GUI中,我只输入了两个必需参数:

In the portal GUI, I input only the two mandatory parameters as so :

WINDOWSFEATURESET_NAME = FS-SMB1
WINDOWSFEATURESET_ENSURE =缺

WINDOWSFEATURESET_NAME = FS-SMB1
WINDOWSFEATURESET_ENSURE = Absent

我尝试以json格式传递不带引号,带引号,双引号的参数,例如['

I'v tried passing the paramaters without quotes, with quotes, double quotes, in a json format like ['FS1-SMB'], nothing works.

我总是收到编译错误,指出:

I always get a compilation error stating :

无法投射类型的对象"System.String"以键入"System.Object []".

除了在使用[object]或[array]作为输入参数时需要json格式的azure自动化运行手册的参考文献之外,我在网上什么都没找到.但这在这里没什么好处.

I found nothing on the web except some reference for azure automation runbooks that needs json format when using [object] or [array] as input parameters. But it does nothing good here.

此外,当使用另一个不使用[array]作为输入参数的复合资源时​​,一切都很好.

Also, when using another composite resource that do not use [array] as input parameter, everything works great.


配置背后的简化"代码是这样的,它可以从工作站上的Powershell控制台正常运行:

The 'simplified' code behind the configuration is like this, and it runs perfecly from my powershell console on my workstation :

Configuration Test {
    param(    
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String[]] $WindowsFeatureSet_Name,
        [String] $WindowsFeatureSet_Ensure
    )
    # resource import
    Import-DscResource –ModuleName PSDscResources

    Node local {
            WindowsFeatureSet WindowsFeatureSet {
            Name = $WindowsFeatureSet_Name
            Ensure = $WindowsFeatureSet_Ensure
        }
    }
}

Test -WindowsFeatureSet_Name 'FS-SMB1' -WindowsFeatureSet_Ensure 'Absent'

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2018-10-16     11:50           1896 local.mof

有人知道这个问题了吗?

Anyone got that issue and a work around it ?

谢谢

大卫

推荐答案

您是否曾尝试期望配置参数为字符串? (然后将其转换为单个资源所需的类型).

Have you tried expecting the configuration parameters to be a string? (and then converting it into the type needed for the individual resources).

例如,这对我有用:

Configuration Test {
    param(    
        [Parameter(Mandatory=


true)] [ValidateNotNullOrEmpty()] [String]
true)] [ValidateNotNullOrEmpty()] [String]


WindowsFeatureSet_Name, [String]
WindowsFeatureSet_Name, [String]


这篇关于Auzure Automation DSC-带有字符串数组输入参数的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆