如何在首次启动时通过命令行在 Server 2012 的 IIS 8.5 中启用“URL Rewrite”模块

How can I enable “URL Rewrite” Module in IIS 8.5 in Server 2012 via the command line at first boot

与问题类似:How can I enable "URL Rewrite" Module in IIS 8.5 in Server 2012? 但通过命令行。

我想创建一个脚本以在 AWS 的 UserData 字段中使用(脚本 运行 在首次启动时配置服务器)并且我想知道安装 URL 通过命令行或其他 Web 平台安装程序项目重写 2.0。

谢谢

我会为此使用 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