I am using Custom Script Extension (CSE) to set the proxy in Windows VMs and then to install antivirus solution. The antivirus solution setup needs internet connection. But it seems that during CSE provisionning the proxy configuration is not taking effect immediately and as a result the antivirus installation fails. Here is my proxy settings script:
Set-ItemProperty -Path 'HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxySettingsPerUser -Value 0
Set-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -Value "123.123.123.123:80"
Set-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -Value 1
netsh winhttp set proxy 123.123.123.123:80
After the CSE provisioning, when I connect to the vm, i see that the proxy is set correctly and able to reach internet. Also, the antivirus solution can be installed by launching the script manually. My problem is that the proxy configuration is not taking effect immediately during the CSE provisionning and antivirus fails because there is no internet.
Here is the part of the policy declaration for CSE deployment:
"resources": [
{
"apiVersion": "2015-06-15",
"copy": {
"count": "[length(variables('vmListArray'))]",
"name": "avAgentCopy"
},
"location": "[parameters('vmLocation')]",
"name": "[concat(trim(variables('vmListArray')[copyIndex()]),'/AntivirusAgent')]",
"properties": {
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"commandToExecute": "[concat ('powershell -ExecutionPolicy Unrestricted -File \"./Scripts/installation-proxy-windows.ps1\" && powershell -ExecutionPolicy Unrestricted -File \"./Scripts/installation-antivirus-windows.ps1\" ')]",
"storageAccountKey": "mykey",
"storageAccountName": "mystorageaccount"
},
"publisher": "Microsoft.Compute",
"settings": {
"fileUris": "[split(variables('fileUris'), ' ')]"
},
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.7"
},
"type": "Microsoft.Compute/virtualMachines/extensions"
}
],
"variables": {
"fileUris": "https://mystorageaccount.blob.core.windows.net/mycontainer/Scripts/installation-antivirus-windows.ps1 https://mystorageaccount.blob.core.windows.net/mycontainer/Scripts/installation-proxy-windows.ps1",
"vmListArray": "[split(parameters('vmList'),',')]"
}
So my question is why Custom Script Extension proxy setting doesn't take effect immediately? Is there a way to overcome this issue or an alternate approach?