Getting all virtual directories for a IIS6 web site using WMI

回眸只為那壹抹淺笑 提交于 2019-12-02 03:15:49

问题


I want to list all virtual directories that belong to a web site with a certain name using WMI and PowerShell.

I know I can list all virtual directories on a server using the code below, but how can I filter out only those that belong to a specific site?

Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2"

回答1:


Well, taking the simplest approach here and filtering based on the properties returned from your given example, I would probably opt to use the site identifier portion in the Name property:

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

The above example only shows virtual directories on the default website that is set up with IIS first install. This always has the identifier 1.

Note: the backtick ` after the bar is the line continuation character (actually it's the escape character, but I'm escaping the EOL,) like _ in Visual Basic. I'm using this so the ugly horizontal scrollbars don't show up in the code block above.

-Oisin



来源:https://stackoverflow.com/questions/3575442/getting-all-virtual-directories-for-a-iis6-web-site-using-wmi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!