我发现,以下博客很有用,因为使用帮助,我能够安装使用传统角色服务的电压器。 我在此有守则,与博客的联系是:
http://www.ithassle.nl 201009/powershell-script-to-install-and-configure-iis7-5/#codesyntax_1
# --------------------------------------------------------------------
# Checking Execution Policy
# --------------------------------------------------------------------
#$Policy = "Unrestricted"
$Policy = "RemoteSigned"
If ((get-ExecutionPolicy) -ne $Policy) {
Write-Host "Script Execution is disabled. Enabling it now"
Set-ExecutionPolicy $Policy -Force
Write-Host "Please Re-Run this script in a new powershell enviroment"
Exit
}
# --------------------------------------------------------------------
# Define the variables.
# --------------------------------------------------------------------
$InetPubRoot = "D:Inetpub"
$InetPubLog = "D:InetpubLog"
$InetPubWWWRoot = "D:InetpubWWWRoot"
# --------------------------------------------------------------------
# Loading Feature Installation Modules
# --------------------------------------------------------------------
Import-Module ServerManager
# --------------------------------------------------------------------
# Installing IIS
# --------------------------------------------------------------------
Add-WindowsFeature -Name Web-Common-Http,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Http-Logging,Web-Request-Monitor,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Performance,Web-Mgmt-Console,Web-Mgmt-Compat,RSAT-Web-Server,WAS -IncludeAllSubFeature
# --------------------------------------------------------------------
# Loading IIS Modules
# --------------------------------------------------------------------
Import-Module WebAdministration
# --------------------------------------------------------------------
# Creating IIS Folder Structure
# --------------------------------------------------------------------
New-Item -Path $InetPubRoot -type directory -Force -ErrorAction SilentlyContinue
New-Item -Path $InetPubLog -type directory -Force -ErrorAction SilentlyContinue
New-Item -Path $InetPubWWWRoot -type directory -Force -ErrorAction SilentlyContinue
# --------------------------------------------------------------------
# Copying old WWW Root data to new folder
# --------------------------------------------------------------------
$InetPubOldLocation = @(get-website)[0].physicalPath.ToString()
$InetPubOldLocation = $InetPubOldLocation.Replace("%SystemDrive%",$env:SystemDrive)
Copy-Item -Path $InetPubOldLocation -Destination $InetPubRoot -Force -Recurse
# --------------------------------------------------------------------
# Setting directory access
# --------------------------------------------------------------------
$Command = "icacls $InetPubWWWRoot /grant BUILTINIIS_IUSRS:(OI)(CI)(RX) BUILTINUsers:(OI)(CI)(RX)"
cmd.exe /c $Command
$Command = "icacls $InetPubLog /grant ""NT SERVICETrustedInstaller"":(OI)(CI)(F)"
cmd.exe /c $Command
# --------------------------------------------------------------------
# Setting IIS Variables
# --------------------------------------------------------------------
#Changing Log Location
$Command = "%windir%system32inetsrvappcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:$InetPubLog"
cmd.exe /c $Command
$Command = "%windir%system32inetsrvappcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:$InetPubLog"
cmd.exe /c $Command
$Command = "%windir%system32inetsrvappcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:$InetPubLog"
cmd.exe /c $Command
#Changing the Default Website location
Set-ItemProperty IIS:SitesDefault Web Site -name physicalPath -value $InetPubWWWRoot
# --------------------------------------------------------------------
# Checking to prevent common errors
# --------------------------------------------------------------------
If (!(Test-Path "C:inetpub empapppools")) {
New-Item -Path "C:inetpub empapppools" -type directory -Force -ErrorAction SilentlyContinue
}
# --------------------------------------------------------------------
# Deleting Old WWWRoot
# --------------------------------------------------------------------
Remove-Item $InetPubOldLocation -Recurse -Force
# --------------------------------------------------------------------
# Resetting IIS
# --------------------------------------------------------------------
$Command = "IISRESET"
Invoke-Expression -Command $Command