Reputation: 12745
I am installing IIS on a windows 10 Pro machine using power shell script. I am using this blog post to create the script.
The script installs IIS with following core.
# * Make sure you run this script from a Powershel Admin Prompt!
# * Make sure Powershell Execution Policy is bypassed to run these scripts:
# * YOU MAY HAVE TO RUN THIS COMMAND PRIOR TO RUNNING THIS SCRIPT!
Set-ExecutionPolicy Bypass -Scope Process
# To list all Windows Features: dism /online /Get-Features
# Get-WindowsOptionalFeature -Online
# LIST All IIS FEATURES:
# Get-WindowsOptionalFeature -Online | where FeatureName -like 'IIS-*'
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment
I have pipelined the task on DevOps:
Everything was working , but today when I started deployment , started getting the error
Enable-WindowsOptionalFeature : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available. At C:\azagent\A1_work_temp\af294c00-d96a-4b04-b507-e2e3afcbee4f.ps1:12 char:1 + Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Enable-WindowsOptionalFeature], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
PowerShell exited with code '1'.
I have checked get-ExecutionPolicy
, which is unrestricted
and $confirmpreference
set to High
.
Why am I getting this error when it was working fine till day before?
Could this be due to windows updates ? How do I get around this issue?
Upvotes: 6
Views: 11188
Reputation: 4727
In my case, the issue was the caused by passing -debug
to the AzurePowerShell task as a script argument.
But the error message is inaccurate, it's showing errors at the place the command is called.
Azure pipeline task which has the same error:
- task: AzurePowerShell@5
inputs:
azureSubscription: '${{ parameters.serviceConnectionName }}'
scriptType: 'FilePath'
errorActionPreference: 'stop'
azurePowerShellVersion: 'OtherVersion'
preferredAzurePowerShellVersion: '9.5.0'
scriptPath: '$(Build.SourcesDirectory)/myScript.ps1'
ScriptArguments: >-
-location "xxx"
...
-debug
My Script:
The error was thrown at line 7 where the command Get-AzResourceGroup -Name 'my-rg' -Location $location
is called.
Once the -debug
argument is removed, the script is working.
Upvotes: 0
Reputation: 5928
As the comment says: the error message indicates that one of your commands is trying to prompt user for confirmation. In case of Enable-WindowsOptionalFeature
, it's probably prompting for reboot.
Usually you can supress prompts by adding -Force
and -Confirm:$false
to Powershell commands.
Additinaly, Enable-WindowsOptionalFeature
has -NoRestart
flag, which should prevent it from prompting for reboot.
Upvotes: 3