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
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.
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.