Can someone please provide me an example on how to execute/invoke the existing customscript extension. I know the document suggested to use timestamp thing but I wasn't able to figure out the powershell script to do it. Help!!
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Thanks for the question! We are investigating and will update you shortly.
Just being more precise.
1.Is there a cmdlt that invokes the existing customextension script?
@roiyz-msft Can you please help answer customer's question? Should the doc contain more info on it? Thanks. :)
@rizwaans I found this blog on Using the Azure Custom Script Extension to execute a PowerShell script multiple times on an Azure Windows VM from an Azure Automation Runbook.
Please check if that helps. Thanks.
@rizwaans Any update? Did that help?
Hi @Karishma-Tiwari-MSFT ,
The provided link didn't help me much.
I am looking for a cmdlet that invokes the existing custom extension script. or Just do I just need to use the "Set- AzureRmVMCustomScriptExtension" cmdlet to execute the already deployed/provisioned script.
Let me take a sample scenario.
@roiyz-msft Did you get a chance to take a look at this question? Thanks.
I've asked @csand-msft to take a look.
@rizwaans Quick answer (haven't tried it yet) based on looking at the examples here: https://github.com/Azure/azure-linux-extensions/tree/master/CustomScript I would try to set the timestamp in the -Settingstring parameter. See section 2.2.2 for the PowerShell and section 3.4 on how to set the timestamp.
@rizwaans Can you please take a look at the suggestion above and see if that helps you. Thanks.
@Karishma-Tiwari-MSFT , @csand-msft I'm little confused here, Are Set-AzureRMVMExtension and Set-AzureRmVMCustomScriptExtension same? Do they both serve the same purpose of running a pre-developed script on VM's
test
@rizwaans This PowerShell script runs the custom extension for every invocation.
Like @csand-msft suggested, I added the timestamp as an argument. So for every execution, Timestamp will have a different value, which changes the configuration of custom script extension.
Because of the configuration change, Extension executes again.
$fileUri = @("https://raw.githubusercontent.com/jakaruna-MSFT/script-for-extension/master/script.ps1")
#get the timestamp (epoch)
$timestamp = Get-Date -UFormat "%s"
$Settings = @{"fileUris" = $fileUri; "timestamp" = $timestamp };
$ProtectedSettings = @{"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File script.ps1"};
#run command
Set-AzureRmVMExtension -ResourceGroupName "my_group" -Location "central us" -VMName "myvm" -Name "custom-script" -Publisher "Microsoft.Compute" -ExtensionType "CustomScriptExtension" -TypeHandlerVersion "1.9" -Settings $Settings -ProtectedSettings $ProtectedSettings
Also note that Custom script extension is designed to execute once. You can consider Desired State Configuration if you want to execute periodically.
Excellent, Thanks very much @jakaruna-MSFT
@jakaruna-MSFT Thanks :)
@rizwaans Glad to know it helped. We will now close this issue. If there are further questions regarding this matter, please reopen it and we will gladly continue the discussion.