使用PowerShell 配置IIS7.0

来源:互联网 发布:python 优点 编辑:程序博客网 时间:2024/04/28 14:37

PowerShell拥有比dos command强大的功能,将取代command成为administrator配置管理系统的工具。

使用PowerShell配置IIS,创建ApplicationPool和web site,修改authentication方案的代码如下:

 

$strName = "SiteName"

$strUsr  = "User"

$strPass = "Password"

$strPath = "C:\"

$strNewURL = http://testSite

#Load WebAdmin Snap-in if needed.   

$iisVersion = Get-ItemProperty "HKLM:\software\microsoft\InetStp";   

if ($iisVersion.MajorVersion -eq 7)   

{    if ($iisVersion.MinorVersion -ge 5) 

   {        Import-Module WebAdministration;    }          

    else    { 

       if (-not (Get-PSSnapIn | Where {$_.Name -eq "WebAdministration";})) 

       {                    Add-PSSnapIn WebAdministration;

        }

    }

}   

 #Create App Pool

New-WebAppPool -Name $strName   

Set-ItemProperty ("IIS:\AppPools\" + $strName) -name processModel.identityType -value 3   

Set-ItemProperty ("IIS:\AppPools\" + $strName) -name processModel.username -value $strUsr   

Set-ItemProperty ("IIS:\AppPools\" + $strName) -name processModel.password -value $strPass          

#Create Web Site   

New-Website –Name $strName –Port 80 –HostHeader $strNewURL –PhysicalPath $strPath   

Set-ItemProperty ("IIS:\Sites\" + $strName) -name applicationPool -value $strName   

Set-ItemProperty ("IIS:\Sites\" + $strName) -name ApplicationDefaults.applicationPool -value $strName   

Set-ItemProperty ("IIS:\Sites\" + $strName) -name ..username -value $strUsr   

Set-ItemProperty ("IIS:\Sites\" + $strName) -name ..password -value $strPass

#Modify authentication setting

Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -location $strName

Set-WebConfigurationProperty -filter /system.webServer/security/authentication/BasicAuthentication -name enabled -value false -PSPath IIS:\ -location $strName

 

更多详细介绍和功能参见:

http://learn.iis.net/page.aspx/447/managing-iis-with-the-iis-70-powershell-snap-in/