IIS 6.0 Windows Server 2003 – 如何使用PowerShell遍历所有网站?

如何使用PowerShell遍历IIS 6.0(Windows Server 2003)上托pipe的所有网站?

有没有办法做到这一点使用WmiObject?

谢谢!

使用ADSI或WMI列出它们如下 –

#ADSI $iis = [ADSI]"IIS://localhost/W3SVC" $iis.psbase.children | where { $_.schemaClassName -eq "IIsWebServer"} | select ServerComment #WMI Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" | Select ServerComment 

要像你在评论中提到的那样添加一个新的HttpCustomHeader,我认为你可以使用下面的技术。 请彻底testing我没有。

 $wmiSiteArray = Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" foreach ($site in $wmiSiteArray) { $path = $site.name + '/root' $vdir = [wmi]"root\MicrosoftIISv2:IIsWebVirtualDirSetting='$path'" $bindingClass= [wmiclass]'root\MicrosoftIISv2:HttpCustomHeader' $newHeader = $bindingClass.CreateInstance() $newHeader.KeyName = "CustomHeader: BlahBlah" $newHeader.value = $null $vdir.HttpCustomHeaders += $newHeader.PSObject.BaseObject $vdir.Put() } 

这篇文章: https : //stackoverflow.com/questions/3575442/getting-all-virtual-directories-for-a-iis6-web-site-using-wmi

有这个解决scheme:

 Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2" | ` Where-Object { $_.name -like "W3SVC/1/*" }