You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Windows自定义脚本扩展执行失败求助:文件下载失败(无效URI错误)

Fixing Azure CustomScriptExtension Deployment Failure for IIS

Hey there, let's get to the bottom of why your CustomScriptExtension is throwing those "invalid URI" errors when trying to install IIS. That error message is a dead giveaway—here's what's going wrong and how to fix it:

What's Causing the Error?

The invalid uri fileUri_{1}/fileUri_{2}/fileUri_{3} messages mean the extension is trying to pull script files from URIs that aren't properly configured. This almost always happens in one of two scenarios:

  • You tried to paste your raw PowerShell script directly into the fileUris field of the extension setup (this field expects URLs to external files, not inline code).
  • You left placeholder values like fileUri_{1} in your configuration and forgot to replace them with actual, valid URLs to your script file.

Solutions to Fix the Issue

Option 1: Run the Script Inline (No External File)

If you don't want to host your script in external storage, you can run the PowerShell commands directly using the commandToExecute field instead of fileUris. Here's how to set this up for common deployment methods:

Azure CLI Example

az vm extension set \
  --resource-group your-resource-group-name \
  --vm-name your-vm-name \
  --name CustomScriptExtension \
  --publisher Microsoft.Compute \
  --settings '{"commandToExecute": "powershell -Command \"Write-Host \\\"Installing IIS service\\\"; Import-Module ServerManager; Add-WindowsFeature Web-Server -IncludeAllSubFeature; Add-WindowsFeature Web-Asp-Net45; Add-WindowsFeature NET-Framework-Features\""}'

ARM Template Example

{
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "apiVersion": "2023-07-01",
  "name": "[concat(parameters('vmName'), '/CustomScriptExtension')]",
  "location": "[parameters('location')]",
  "properties": {
    "publisher": "Microsoft.Compute",
    "type": "CustomScriptExtension",
    "typeHandlerVersion": "1.10",
    "settings": {
      "commandToExecute": "powershell -Command \"Write-Host \\\"Installing IIS service\\\"; Import-Module ServerManager; Add-WindowsFeature Web-Server -IncludeAllSubFeature; Add-WindowsFeature Web-Asp-Net45; Add-WindowsFeature NET-Framework-Features\""
    }
  }
}

Note: We added Write-Host instead of a raw string for better logging, and properly escaped quotes for the command.

Hosting your script in Azure Blob Storage makes it easier to update and reuse. Here's the step-by-step:

  1. Save your script as a .ps1 file (e.g., Install-IIS.ps1) with this content:

    Write-Host "Installing IIS service"
    Import-Module ServerManager
    Add-WindowsFeature Web-Server -IncludeAllSubFeature
    Add-WindowsFeature Web-Asp-Net45
    Add-WindowsFeature NET-Framework-Features
    
  2. Upload the file to Azure Blob Storage:

    • Create a storage account (if you don't have one) and a blob container.
    • Upload the .ps1 file. Make the blob public (or generate a SAS token for private access).
  3. Update your extension configuration:
    Use the blob's URI in the fileUris field, and set commandToExecute to run the downloaded script. Here's an ARM template example:

    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2023-07-01",
      "name": "[concat(parameters('vmName'), '/CustomScriptExtension')]",
      "location": "[parameters('location')]",
      "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.10",
        "settings": {
          "fileUris": [
            "https://your-storage-account.blob.core.windows.net/your-container/Install-IIS.ps1"
          ],
          "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File Install-IIS.ps1"
        }
      }
    }
    

    If using a SAS token, append it to the URI: https://your-storage-account.blob.core.windows.net/your-container/Install-IIS.ps1?your-sas-token-here

Quick Troubleshooting Checks

  • Double-check your URI for typos in storage account name, container name, or blob filename.
  • If using a private blob, confirm your SAS token is valid (not expired, has read permissions).
  • Test connectivity from the VM: Log into the VM and run Invoke-WebRequest -Uri "your-script-uri" to make sure it can download the file.

内容的提问来源于stack exchange,提问作者Shiv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 10:38:12