actually, I´m trying to create a Azure runbook with a Custom Script Execution. The runbook run against a Linux VM. I build a simple script which create a directory on the VM. If I execute the runbook the first time, then the directory will be created instantely. Then, I delete the directory, run the runbook again and the directory is not created again. After some researching on the internet, I found a hint, that you can only run a script with the same parameters on a virtual machine once. So I added a timestamp in my SettingString. Unfortunately, either this doesn´t solve the problem or I have an error in my code.
Hopefully you can help me out to find my error or give me an hint, how it is possible to execute a script multiple times against the same VM.
Thanks a lot!
$timestamp = (Get-Date).Ticks
Write-Output $timestamp
$SettingsString = '{"timestamp": "$timestamp", "fileUris":["myURI"],"commandToExecute":"sh myscript.sh"}';
$ProtectedSettingsString = '{"storageAccountName": "xxx","storageAccountKey":"xxx"}'
Set-AzureRmVMExtension -ResourceGroupName "xxx" -Location "xxx" -VMName "xxx" -Name "xxx" -Publisher "Microsoft.OSTCExtensions" -ExtensionType "CustomScriptForLinux" -TypeHandlerVersion 1.5 -SettingString $SettingsString -ProtectedSettingString $ProtectedSettingsString
You can use Set-AzVMExtension
with -ForceRerun
parameter to achieve this, you need to pass in a different string each time.
https://learn.microsoft.com/en-us/powershell/module/az.compute/set-azvmextension?view=azps-1.3.0