Azure-docs: Execute custom script more than once.

Created on 7 Nov 2018  Â·  15Comments  Â·  Source: MicrosoftDocs/azure-docs

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


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

cxp product-question triaged virtual-machines-windowsvc

All 15 comments

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?

  1. what happens when I run the same Set-AzureRMVMCustomScriptExtension "mytestscript" more than once. Does it overwrites the existing script?

@roiyz-msft Can you please help answer customer's question? Should the doc contain more info on it? 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.

  1. I want to run a script on my virtual machine that captures the information of the services running and save it to a text file.
  2. Deployed a custom extension script (_myCustomExtScript_)and it is provisioned successfully.
  3. I again want to run the same script to capture the information of services running, So I want to execute the already deployed myCustomExtScript.
    So, Is there any separate cmdlet to execute or just the same Set- AzureRmVMCustomScriptExtension

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

Was this page helpful?
0 / 5 - 0 ratings