How can I pass multiple arguments to Set-AzureRmVMCustomScriptExtension?

后端 未结 2 1688
旧时难觅i
旧时难觅i 2021-01-21 16:54

The Azure Cmdlet for adding a Custom Script Extension to a VM named Set-AzureRmVMCustomScriptExtension has an -Argument switch, which states that it accepts a strin

相关标签:
2条回答
  • 2021-01-21 17:06

    Not sure if there is a difference between the ASM (classic) and ARM version of this cmdlet but for me, I had to do it thus (parameters missing for clarity):

    $arguments = "-arg1 'foo' -arg2 'bar' -arg3 'cat'"
    
    Set-AzureRmVMCustomScriptExtension `
        -Argument $Arguments `
        -Run "SomeScript.ps1"
    

    SomeScript.ps1 would look something like:

    param
    (
        [string]$arg1,
        [string]$arg2,
        [string]$arg3
    )
    
    function SomeFunction
    {
        Write-Host $arg1
        Write-Host $arg2
        Write-Host $arg3
    
        #Do something here...
    }
    SomeFunction -arg1 $arg1 -arg2 $arg2 -arg3 $arg3 #Call the function from within SomeScript.ps1
    

    If you could actually see the output of Write-Host when run from a Custom Script Extension, it would result in an output of :

    foo
    bar
    cat
    

    HTH.

    0 讨论(0)
  • 2021-01-21 17:15

    There is an example of multiple arguments in use from this blog:

    Set-AzureVMCustomScriptExtension -VM $x -ContainerName 'test' -FileName 'script1.ps1','script2.ps1','script3.ps1' -Run 'script1.ps1' -Argument 'arg1 arg2' 
          | Update-AzureVM  
    

    If this code snipett actually works then it means you need to pass a space delimited string for your arguments. Just make sure you keep your double quotes so the variables expand properly.

    0 讨论(0)
提交回复
热议问题