Como @modo mencionou no comentário, você pode usar a extensão de script personalizada "para alcançar este objetivo.
Se você estiver usando o ARM VM:
$RGName = '<resource-group-name>'
$VmName = '<vm-name>'
$Location = '<location>'
$ExtensionName = 'CustomScriptForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version = '<version>'
$PublicConf = '{
"fileUris": ["<url>"],
"commandToExecute": "<command>"
}'
$PrivateConf = '{
"storageAccountName": "<storage-account-name>",
"storageAccountKey": "<storage-account-key>"
}'
Set-AzureRmVMExtension -ResourceGroupName $RGName -VMName $VmName -Location $Location '
-Name $ExtensionName -Publisher $Publisher '
-ExtensionType $ExtensionName -TypeHandlerVersion $Version '
-Settingstring $PublicConf -ProtectedSettingString $PrivateConf
Se você estiver usando o ASM VM:
$VmName = '<vm-name>'
$vm = Get-AzureVM -ServiceName $VmName -Name $VmName
$ExtensionName = 'CustomScriptForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version = '<version>'
$PublicConf = '{
"fileUris": ["<url>"],
"commandToExecute": "<command>"
}'
$PrivateConf = '{
"storageAccountName": "<storage-account-name>",
"storageAccountKey": "<storage-account-key>"
}'
Set-AzureVMExtension -ExtensionName $ExtensionName -VM $vm '
-Publisher $Publisher -Version $Version '
-PrivateConfiguration $PrivateConf -PublicConfiguration $PublicConf |
Update-AzureVM