1

To do this with a script that is publicly available this is no Problem using:

$publicSettings = @{
    "fileUris" = (,"$uri");
    "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File azure_cse_vm_initial_script.ps1 $argument"
}

Write-Host "  ==> Add-AzureRmVmssExtension"
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss `
    -Name "customScript" `
    -Publisher "Microsoft.Compute" `
    -Type "CustomScriptExtension" `
    -TypeHandlerVersion 1.8 `
    -Setting $publicSettings

But how to do in case I use a storage account with a blob container? Can the access key be added to the Settings object? But how? And what to use for the URL.

The script I want to run should not be public accessible because it is the Installation script of my application.

Thanks, Daniel

Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
Daniel W.
  • 938
  • 8
  • 21

2 Answers2

2

I would create a shared access signatur for that script (see Using shared access signatures). Then you can simple add the SAS token to the URI. E. g:

https://myaccount.blob.core.windows.net/sascontainer/sasblob.txt?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
0

You could also use storage account name and storage account key to download the script: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows#extension-schema

Neil Sant Gat
  • 857
  • 6
  • 10
  • This works fine for Add-AzureRmVmExtension but as far as I understand I need to use Add-AzureRmVmssExtension for Scale Sets, where I have non of those Parameters. – Daniel W. May 22 '18 at 10:35
  • 1
    You need to encode this information in the "Settings" and/or "ProtectedSettings" parameters mentioned here: https://learn.microsoft.com/en-us/powershell/module/azurerm.compute/add-azurermvmssextension?view=azurermps-6.1.0. The schema for these objects can be found here: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows#extension-schema – Neil Sant Gat May 23 '18 at 19:14