
Set-AzVMExtension -ResourceGroupName $RGName -Location $Location -VMName $VMName -Name $Extensions.Type -Publisher $Extensions.PublisherName -ExtensionType $Extensions.Type -TypeHandlerVersion $ExtensionVersion -Settings $ScriptSettings -ProtectedSettings $ProtectedSettings $ScriptSettings = $CustomScriptStorageAccountName "storageAccountKey" = $StorageAccountKey "commandToExecute" = $CommandToExecute} $ExtensionVersion = $Extensions.Version -join "" $Extensions = Get-AzVMExtensionImage -Location $Location -PublisherName "" -Type "CustomScript" Write-Output -InputObject "Adding custom script extension to VM" # Add custom script extension to Linux VM $ScriptLocation = $ScriptBlobUrl + "$ContainerName/" + $CustomScriptFileName Set-AzStorageBlobContent -File $FilePath -Container $ContainerName -Blob $CustomScriptFileName -Context $Context Write-Output -InputObject "Uploading custom script extension to storage account" # Upload script extension to the storage account $StorageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $RGName -Name $CustomScriptStorageAccountName).Value $Container = New-AzStorageContainer -Name $ContainerName -Context $Context $StorageAccount = New-AzStorageAccount -Location $Location -ResourceGroupName $RGName -Type "Standard_LRS" -Name $CustomScriptStorageAccountName Write-Output -InputObject "Creating storage account and container" $CommandToExecute = "sh $CustomScriptFileName $ScriptArguments" $FilePath = " C:\Users\User1\SetRootPassword.sh" $CustomScriptStorageAccountName = " customscript ".ToLower() $ContainerName = " customscriptextension"


$CustomScriptFileName = " SetRootPassword.sh" The name of the container created in the storage blobĪdd the following code to the end of the VM creation script when creating a Linux VM on Azure Stack Hub.

The Azure Resource Manager endpoint for Azure Stack Hub Declare variablesĮnter details below to provide values for the variables in the following scripts in this article: Variable name To complete the steps in this article, you must have appropriate access to a subscription in the Azure Stack Hub portal. There are two options for deploying custom script extensions:ĭeploy a custom script extension from your local disk.ĭeploy a custom script extension using a file URI. This article explains how to add custom script extensions to new and existing VMs on Azure Stack Hub. Custom script extensions are useful for post deployment configuration, software installation, or any other configuration or management tasks. How to configure custom script extensions for new and existing VMs on Azure Stack Hub OverviewĬustom script extensions download and execute scripts on Azure Stack Hub virtual machines.
