Search code examples
azurepowershellazure-powershell

Running the Set-AzVMRunCommand command with parameters produces strange failing file on destination


I am using the Set-AzVMRunCommand command with the -Parameter parameter set.

Here is my code:

    $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

Please note the line above starting with -Parameter as this is the line that is causing me problems.

And here is the local script that gets sent to the destination virtual machine by the Set- AzVMRunCommand:

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

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

However, the script that ends up on the virtual machine as as follows:

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

Notice all the extra semi-colons (;).

Can anyone help me out understanding what is going on as I have spent all day on this.

cheers Russ


Solution

  • Looks like this is currently an Azure Powershell bug with multiline script files:

    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.


    For -Parameter, you may need to restructure your hash table like this:

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