使用set-azuremrmvmcustomscriptextension执行DSC文件 [英] Execute DSC File with set-azuremrmvmcustomscriptextension
问题描述
我试图通过Azure Automation Runbook中的set-azuremrmvmcustomscriptextension执行DSC脚本.
I am trying to execute a DSC script via set-azuremrmvmcustomscriptextension within an Azure Automation Runbook.
我不想使用Azure自动化的DSC,因为我的运行簿中需要执行其他操作(非DSC),并且我不想使用set-azurermvmdscextension,因为我的文件不在Blob存储中但是可以通过set-azurermvmcustomscriptextension提供的fileURI开关进行访问.
I do not want to use Azure Automation's DSC since there are other actions in my runbook I need to execute (non-DSC) and I don't want to use the set-azurermvmdscextension as my file is not located in Blob storage but accessible via the fileURI switch offered by set-azurermvmcustomscriptextension.
当我通过set-azurermvmcustomscriptextension运行DSC文件(.ps1)时,没有任何错误,它会生成本地.mof.但是,它实际上并没有执行配置括号(即需要运行的DSC PowerShell代码)内的任何内容.
When I run a DSC file (.ps1) via set-azurermvmcustomscriptextension, I get no errors and it generates the local .mof. However, it doesn't actually execute anything within the configuration brackets, aka, the DSC PowerShell code that needs to run.
.ps1具有DSC命令以应用配置.如果我在通过PowerShell ISE远程将脚本运行到服务器上时运行了脚本,则仅当我从set-azurermvmcustomscriptextension调用它时,它不会执行配置(但仍会创建mof).
The .ps1 has the DSC command to apply the configuration. If I run the script while remoted onto the server via PowerShell ISE it runs, it's only when I call it from set-azurermvmcustomscriptextension that it doesn't execute the configuration (but still creates the mof).
正在播放权限问题吗?我相信DSC在系统级别运行,并且在导入模块等方面不会产生mof/no错误,这没有问题.这就像是在忽略配置一样.
Is there a permissions issue at play? DSC runs at the system level I believe and it had no issues generating the mof/no errors on importing modules, etc. It's like it is just ignoring the configuration.
更新1
经过更多测试,我们发现当我们在Set-AzureRMVMCustomScriptExtension中使用-Argument时,它将无法运行DSC配置.删除它可以使DSC配置运行.但是,我们需要从Runbook/Set-AzureRMVMCustomScriptExtension中传递正确的参数,以使其具有正确的值.
After more testing, we have found that when we use -Argument in Set-AzureRMVMCustomScriptExtension, it fails to run the DSC Configuration. Removing it allows the DSC Configuration to run... however, we need to pass the correct Arguments in from the Runbook/Set-AzureRMVMCustomScriptExtension in order for it to have the correct values.
在这里我们找到了Args:如何我将多个参数传递给Set-AzureRmVMCustomScriptExtension?
Here is where we figured out the Args: How can I pass multiple arguments to Set-AzureRmVMCustomScriptExtension?
推荐答案
经过多次尝试并找出了我如何通过-Argument开关传递参数的问题后,我发现我的一个参数中包含空格,因此我尝试按以下方式调用参数,因为-Argument是用空格分隔的,所以它将单个参数视为多个,并且未按预期将其传递到我的脚本中.注意:Azure自动化运行手册将提示输入以下值:
After multiple attempts and isolating the issue being how I am passing arguments via the -Argument switch, I found that one of my arguments had spaces in it, so that I tried to call argument as follows, it saw the single argument as multiple and did not pass this into my script as expected since -Argument is space delimited. NOTE: The Azure Automation Runbook Prompts for the values:
Input for Value 1: myvalue1
Input for Value 2: my value 2
[parameter(Mandatory=$true)][String] $value1,
[parameter(Mandatory=$true)][String] $value2
-Argument "$value1 value2"
# Value 1 seen as myvalue1, while Value 2 seen as three separate values of "my" "value" "2" since -Argument is space delimited.
对此进行更改以转义$ value2参数可解决此问题,如下所示:
Changing this to escape the $value2 argument fixed the issue as follows:
Input for Value 1: myvalue1
Input for Value 2: my value 2
[parameter(Mandatory=$true)][String] $value1,
[parameter(Mandatory=$true)][String] $value2
-Argument "$value1 `"value2`""
# Value 1 seen as myvalue1, while Value 2 seen as "my value 2"
这篇关于使用set-azuremrmvmcustomscriptextension执行DSC文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!