gpt4 book ai didi

azure - 运行带参数的 Set-AzVMRunCommand 命令会在目标上生成奇怪的失败文件

转载 作者:行者123 更新时间:2023-12-03 02:02:11 25 4
gpt4 key购买 nike

我正在使用带有 -Parameter 参数集的 Set-AzVMRunCommand 命令。

这是我的代码:

    $VMRun = Set-AzVMRunCommand `
-ResourceGroupName $customerVirtualMachine.ResourceGroupName `
-RunCommandName "RunPowerShellScript" `
-VMName $customerVirtualMachine.Name `
-Location $customerVirtualMachine.Location `
-ScriptLocalPath "scripts\$($desinationScriptFile)" `
-DefaultProfile $ctx `
-OutputBlobUri $outputBlobUri `
-ErrorBlobUri $errorBlobUri `
-Parameter @(@{Name='PerformDataLoad'; Value='True'; }) `
-ErrorAction Stop

请注意上面以 -Parameter 开头的行,因为这是导致我出现问题的行。

下面是通过 Set-AzVMRunCommand 发送到目标虚拟机的本地脚本:

param (
[Parameter(Mandatory = $false)]
[string]
$PerformDataLoad
)

Write-Output "The value of PerformDataLoad is: $PerformDataLoad"

但是,最终在虚拟机上运行的脚本如下:

param (; 
[Parameter(Mandatory = $false)];
[string]; $PerformDataLoad; );
;
;
Write-Output "The value of PerformDataLoad is: $PerformDataLoad"

注意所有额外的分号 (;)。

任何人都可以帮助我了解发生了什么事,因为我花了一整天的时间。

干杯拉斯

最佳答案

目前看来,这是一个带有多行脚本文件的 Azure Powershell 错误:

https://github.com/Azure/azure-powershell/issues/21131

Workaround

Instead of using ScriptLocalPath parameter, use SourceScript parameter, with Get-Content "your path to script.ps1" | Out-String and everything will be fine.

<小时/>

对于 -Parameter,您可能需要像这样重构哈希表:

-Parameter @{PerformDataLoad='True'; Param2='Value2'}

关于azure - 运行带参数的 Set-AzVMRunCommand 命令会在目标上生成奇怪的失败文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75760369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com