Web Administration (IIS) Provider for Windows PowerShell
Windows PowerShell 是微軟為Windows環境所開發的殼程式(shell)及腳本語言技術,採用的是命令列介面,並是以.NET Framework技術為基礎,這項技術提供了多元控制與自動化的系統管理能力。
WebAdministration 使用限制為只支援Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista以上版本的OS。
PowerShell Web Administration 可以針對 IIS(Internet Information Services)進行操作,
在這邊要跟大家分享幾個常用的 PowerShell Web Administration 指令,
Get-Host | Select-Object Version
Import-Module WebAdministration
Get-ChildItem IIS:\Sites
New-Item IIS:\Sites\站台名稱 -bindings @{protocol='http';bindingInformation=':Port:URL or IP'} -PhysicalPath 站台路徑
Rename-Item IIS:\Sites\舊名稱 新名稱
Remove-Item IIS:\Sites\站台名稱
Get-ChildItem IIS:\AppPools
.NET C# 的開發者若需要控制到IIS 這時候 PowerShell 就是一個好用的東西,提供簡易C#語法:
using (PowerShell powershell = PowerShell.Create()) { // 導入 WebAdministration 模組 powershell.AddScript("Import-Module WebAdministration"); // 建置 IIS 站台 語法 powershell.AddScript(@"New-Item IIS:\Sites\站台名稱 -bindings @{protocol='http';bindingInformation=': 站台Port:站台URL'} -PhysicalPath 站台路徑"); // 執行 PowerShell 語法 powershell.Invoke(); }