简体   繁体   中英

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

Similar to the question: How can I enable "URL Rewrite" Module in IIS 8.5 in Server 2012? but via command line.

I want to create a script to use in the UserData field in AWS (scripts that are run on first boot to configure the server) and I was wondering on the best way to install URL Rewrite 2.0 via the command line or other Web Platform Installer items.

Thanks

I would use chocolatey for this. In fact, I have a set of functions I tend to use to make this easier. Save this script somewhere and call it from your UserData script:

<#
.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM