Azurerm virtual machine extension

Hi,

I want to execute powershell in a remote machine. Script I used for the same is pasted below. Powershell file is saved in Azure Blob Storage.

resource “azurerm_virtual_machine_extension” “software” {
name = “vm-ir-poc-devopsagent”
virtual_machine_id = azurerm_windows_virtual_machine.vmWindows.id
publisher = “Microsoft.Azure.Extensions” #“Microsoft.Compute”
type = “CustomScriptExtension”
type_handler_version = “2.0”
auto_upgrade_minor_version = “true”

protected_settings = <<PROTECTED_SETTINGS
{
“commandToExecute”: “powershell.exe -Command "./gatewayInstall.ps1 ‘IR@497119c8-0010-47e3-8fbb-63d10c8b9999@adf-poc-05-medium09@ServiceEndpoint=adf-poc-05-medium09.canadacentral.datafactory.azure.net@BgP3qsHN1XI0mhvAAAAdO5wp3fD4KM7tpAAaaO2Dt0o=’; exit 0;"”
}
PROTECTED_SETTINGS
settings = <<SETTINGS
{
“fileUris”: [
https://rg9c06.blob.core.windows.net/powerscript/gatewayInstall.ps1
]
}
SETTINGS
}

When I am trying to execute powershell in remote machine facing below error

Error: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=404 – Original Error: Code=“ArtifactNotFound” Message="The VM extension with publisher ‘Microsoft.Azure.Extensions’ and type ‘CustomScriptExtension’ could not be found.

Please help me to resolve the above issue

here is my working code. Replace the XXX with your values
resource “azurerm_virtual_machine_extension” “powershell” {

count = length(var.instances)

name = “runpowershell”

virtual_machine_id = azurerm_windows_virtual_machine.vm.*.id[count.index]

depends_on = [azurerm_windows_virtual_machine.vm]

publisher = “Microsoft.Compute”

type = “CustomScriptExtension”

type_handler_version = “1.10”

settings = <<SETTINGS

{

“fileUris”: [“https://xxxxxx.blob.core.windows.net/scripts/deployment.ps1”]

}

SETTINGS

protected_settings = <<PROTECTED_SETTINGS

{

“storageAccountKey”: “xxxxxxxxx”,

“storageAccountName”: “txxxx”,

“commandToExecute”: “powershell -ExecutionPolicy Unrestricted -File deployment.ps1”

}

PROTECTED_SETTINGS

}

Thanks for your support. Works for me