danielsollondon / azvmimagebuilder

Azure VM Image Builder
180 stars 153 forks source link

Using powershell customizer to enable windows feature fails when using ps1 script, succeeds otherwise #105

Closed ranjit01 closed 3 years ago

ranjit01 commented 3 years ago

Repro steps:

#Requires -RunAsAdministrator Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" Write-Host "Enable feature: KeyboardFilter" Enable-WindowsOptionalFeature -Online -FeatureName Client-KeyboardFilter -All -NoRestart

My customizer in azure image builder json looks like this:

"customize": [ { "type": "PowerShell", "name": "Run ConfigureOS.ps1", "runElevated": true, "scriptUri": "https://myazurestoragefoobar.blob.core.windows.net/mycontainer/ConfigureOS.ps1" }, { "type": "WindowsRestart", "restartCommand": "shutdown /r /f /t 0", "restartTimeout": "5m" },

Expected result: Successful run of configureOS.ps1 as part of image builder.

Actual result: Build fails, and only line in customization.log is below. Does not give much information about what really went wrong. ` ResourceNotFound

The specified resource does not exist. RequestId:add1720f-e01e-0004-5f7b-065723000000 Time:2021-02-19T04:55:52.5639151Z

`

I also tried as part of customization to download ConfigureOS.ps1 file locally using file customizer and the executing it locally, but even that didn't work and I got same error in customization.log

What works? Instead of trying to enable windows feature from a ps1 script, if I directly add that command as inline in a powershell customizer, that works fine! Basically, following works:

"customize": [ { "type": "PowerShell", "name": "Enable Windows optional feature - KeyboardFilter", "inline": [ "Enable-WindowsOptionalFeature -Online -FeatureName Client-KeyboardFilter -All -NoRestart" ], "runElevated": true }, { "type": "WindowsRestart", "restartCommand": "shutdown /r /f /t 0", "restartTimeout": "5m" },

danielsollondon commented 3 years ago

Hi @ranjit01 - Can you raise a case here and I will triage this with the CSS team please? https://github.com/danielsollondon/azvmimagebuilder/blob/master/troubleshootingaib.md#troubleshooting-azure-vm-image-build-aib-failures