Sim*_*ons 6 powershell tfs devops azure-devops azure-pipelines
我正在使用 Power Shell 脚本在 Windows 10 Pro 机器上安装 IIS。我正在使用这篇博文来创建脚本。
该脚本使用以下核心安装 IIS。
# * 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
Run Code Online (Sandbox Code Playgroud)
我已经在 DevOps 上流水线化了任务:
一切正常,但今天当我开始部署时,开始出现错误
Enable-WindowsOptionalFeature :Windows PowerShell 处于非交互模式。读取和提示功能不可用。在 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 退出,代码为“1”。
我已经检查过 get-ExecutionPolicy,这是unrestricted并 $confirmpreference设置为High.
为什么我在前一天工作正常时会收到此错误?
这可能是由于Windows更新吗?我该如何解决这个问题?
正如评论所说:错误消息表明您的命令之一正在尝试提示用户确认。如果是Enable-WindowsOptionalFeature,可能会提示重新启动。
通常,您可以通过向 Powershell 命令添加-Force和来抑制提示。-Confirm:$false
另外,Enable-WindowsOptionalFeature有-NoRestartflag,这应该可以防止它提示重新启动。