ET WebClient classes 来实现这个请求:
$webclient = New-Object Net.WebClient
$webclient.DownloadString("http://localhost:8080/");
$webclient.DownloadString("http://localhost:8080/DemoApp");
$webclient.DownloadString("http://localhost:8080/DemoVirtualDir1");
$webclient.DownloadString("http://localhost:8080/DemoApp/DemoVirtualDir2");
If you feeling adventurous you can also use Internet Explorer object itself:
$ie = new-object -com InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate(http://localhost:8080/);
总结
本文中,您了解了如何使用PowerShell创建WEB站点, Web Applications, 虚拟目录和应用程序池.
除此之外,我们还使用 PowerShell 创建了一个功能(函数)化的完整方案.
当然除了上面的方式来管理IIS站点之外,还可以使用Microsoft.Web.Administration(该dll位于"Windows\System32\inetsrv 目录下)。下面的PS脚本就是实现指量创建,删除等站点操作功能的:
function Setup-IIS { param([int]$NumSites) for($i=0 ; $i -lt $NumSites ; $i++) { $Appfolder = "c:\inetpub\webroot\Site$i" if (-not (test-path $Appfolder)) { md $AppFolder -force | out-null $defaultHTM = "$Appfolder\default.htm" echo "This is site $i" | out-file $defaultHTM } } } function Cleanup-IIS { param([int]$NumSites) [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") $mgr = new-object Microsoft.Web.Administration.serverManager for($i=0 ; $i -lt $NumSites ; $i++) { $AppPoolName= "AppPool_$i" $SiteName = "WebSite_$i" $Appfolder = "c:\inetpub\webroot\Site$i" $mgr.Sites.Remove($mgr.Sites[$SiteName]) $mgr.ApplicationPools.Remove($mgr.ApplicationPools[$AppPoolName]) if (test-path $Appfolder) { rd $Appfolder -recurse } } $mgr.CommitChanges() } function Makewebs-IIS { param([int]$NumSites) $start = get-date [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") | out-null $mgr = new-object Microsoft.Web.Administration.serverManager for($i=0 ; $i -lt $NumSites ; $i++) { $AppPoolName= "AppPool_$i" $SiteName = "WebSite_$i" $portNumber = 8000 + $i $mgr.ApplicationPools.Add($AppPoolName) | out-null $Appfolder = "c:\inetpub\webroot\Site$i" $site = $mgr.Sites.Add($SiteName,$Appfolder,$portNumber) $site.ServerAutoStart = $true $app = $site.Applications[0] $app.ApplicationPoolName = $AppPoolName #$site.Bindings.Add("*:$portNumber:", "http") | out-null } $mgr.CommitChanges() $duration = [DateTime]::Now - $start write-host "Total seconds: " + $duration.TotalSeconds.Tostring() }
我们只要以“管理员身份”运行Powershell,并在命令行下输入如下(以创建站点为例)代码:
>Makewebs-IIS10
这样就会批量创建10web站点了:)
好了,今天的内 |