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

问题描述 投票:0回答:1

我正在使用带有

Set-AzVMRunCommand
参数集的
-Parameter
命令。

这是我的代码:

    $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 azure-powershell
1个回答
0
投票

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

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

解决方法

不使用 ScriptLocalPath 参数,而是使用 SourceScript 参数,使用 Get-Content "your path to script.ps1" | Out-String 一切都会好起来的。


对于

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

-Parameter @{PerformDataLoad='True'; Param2='Value2'}
© www.soinside.com 2019 - 2024. All rights reserved.