How can I pass multiple arguments to Set-AzureRmVMCustomScriptExtension?

后端 未结 2 1687
旧时难觅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.

提交回复
热议问题