站點配置代碼
01 ? ?$appSitePath =?"iis:\sites\Default Web Site\MyWebSite" ? ?
02 ? ?$existWeb = Test-Path $appSitePath ? ?
03 ? ?? ? ?
04 ? ?if($existWeb -eq $false) { ? ?
05 ? ?????$folderPath = $folderPath =?"d:\WebApp\MyWeb" ? ?
06 ? ?????$appPoolName =?"My AppPool" ? ?
07 ? ?? ? ?
08 ? ?????New-Item $appSitePath -physicalpath $folderPath -type Application ? ?
09 ? ?? ? ?
10 ? ?????#設定剛剛建立的application pool ? ?
11 ? ?????Set-ItemProperty $appSitePath -name applicationpool -value $appPoolName ? ?
12 ? ?????? ? ?
13 ? ?????$appSiteShortName = $appSitePath.ToLower().Replace("iis:\sites\", "").Replace("\", "/") ? ?
14 ? ?? ? ?
15 ? ?????#開啟window authentication ? ?
16 ? ?????Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value?true?-PSPath IIS:\ -location $appSiteShortName ? ?
17 ? ?? ? ?
18 ? ?????#關閉anonymous authentication ? ?
19 ? ?????Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value?false?-PSPath IIS:\ -location $appSiteShortName ? ?
20 ? ?? ? ?
21 ? ?????#移除預設的首頁並重新設定 ? ?
22 ? ?????Remove-WebConfigurationproperty -filter /system.webserver/defaultdocument -name files -PSPath IIS:\ -location $appSiteShortName ? ?
23 ? ?????Add-WebConfiguration -filter /system.webserver/defaultdocument/files -atIndex 0 -value @{value =?"default.aspx"} -PSPath IIS:\ -location $appSiteShortName ? ?
24 ? ?} ? ?