与问题相似:How can I enable "URL Rewrite" Module in IIS 8.5 in Server 2012?但是通过命令行。
我想创建一个在AWS的UserData字段中使用的脚本(在首次启动时运行的脚本来配置服务器),我想知道通过命令行或其他Web安装URL Rewrite 2.0的最佳方法平台安装程序项目。
由于
答案 0 :(得分:3)
我会使用chocolatey。事实上,我有一套功能,我倾向于使这更容易。将此脚本保存在某处并从UserData脚本中调用它:
<#
.description
Get the PATH environment variables from Machine, User, and
Process locations, and update the current Powershell
process's PATH variable to contain all values from each of
them. Call it after updating the Machine or User PATH value
(which may happen automatically during say installing
software) so you don't have to launch a new Powershell
process to get them.
#>
function Update-EnvironmentPath {
[CmdletBinding()] Param()
$oldPath = $env:PATH
$machinePath = [Environment]::GetEnvironmentVariable("PATH", "Machine") -split ";"
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User") -split ";"
$processPath = [Environment]::GetEnvironmentVariable("PATH", "Process") -split ";"
$env:PATH = ($machinePath + $userPath + $processPath | Select-Object -Unique) -join ";"
Write-EventLogWrapper -message "Updated PATH environment variable`r`n`r`nNew value: $($env:PATH -replace ';', "`r`n")`r`n`r`nOld value: $($oldPath -replace ';', "`r`n")"
}
# Install Chocolatey itself:
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
# NOTE: Chocolatey changes the system %PATH%, so we have to get the latest update here:
Update-EnvironmentPath
# Configure Chocolatey to not require confirmation when installing packages:
choco.exe feature enable --name=allowGlobalConfirmation --yes
# Install the package we care about
choco.exe install urlrewrite