如何使用WMI获取IIS应用程序(虚拟文件夹)的实际目录path?
使用Scriptomatic V2工具来查看更多样本:
在错误恢复下一步
const wbemFlagReturnImmediately =&h10
常量wbemFlagForwardOnly =&h20
arrComputers = Array(“*”)
对于每个strComputer在arrComputers
WScript.Echo
WScript.Echo“==========================================”
WScript.Echo“计算机:”&strComputer
WScript.Echo“==========================================”
设置objWMIService = GetObject(“winmgmts:\”&strComputer&“\ root \ MicrosoftIISv2”)
设置colItems = objWMIService.ExecQuery(“SELECT * FROM IIsWebVirtualDir_IIsWebVirtualDir”,“WQL”,_
wbemFlagReturnImmediately + wbemFlagForwardOnly)
对于每个对象在colItems中
WScript.Echo“GroupComponent:”&objItem.GroupComponent
WScript.Echo“PartComponent:”&objItem.PartComponent
WScript.Echo
下一个
下一个
当然,这是3岁,但这是一个很好的小问题。 如果解决方案必须使用.NET的规范包括PowerShell,那么这将做的伎俩。 有人可能想知道某一天:
$server = 'serverName' $query = "Select Path From IIsWebVirtualDirSetting WHERE Name = 'W3SVC/1/ROOT'" Get-WmiObject -namespace "root/microsoftiisv2" -query $query -computername $server -authentication 6
结果对象将包含一个名为“路径”的属性。
这是纯粹的.Net选项,应该返回与Isalamon的答案相同的结果。
从我的WmiMacros
示例用法(替换strComputer
)
Macros.WmiMacros.QueryWmiAdvanced (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT * FROM IIsWebVirtualDir_IIsWebVirtualDir" |> Seq.map (fun e-> e.Properties.["GroupComponent"].Value, e.Properties.["PartComponent"].Value)
远远更详细的用法:
let webserverSettings = Macros.WmiMacros.QueryWmiAdvanced (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT Name,serverComment FROM IIsWebserverSetting" |> Seq.map (fun e -> e.Properties.["Name"].Value,e.Properties.["serverComment"].Value) let webVirtualDirs = Macros.WmiMacros.QueryWmiAdvanced (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT AppRoot,Name FROM IIsWebVirtualDir" |> Seq.map (fun e -> e.Properties.["Name"].Value,e.Properties.["AppRoot"].Value) let webVirtualDirSettings = Macros.WmiMacros.QueryWmiAdvanced (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT Name,Path,AppPoolId FROM IIsWebVirtualDirSetting" |> Seq.map (fun e -> e.Properties.["Name"].Value,e.Properties.["Path"].Value,e.Properties.["AppPoolId"].Value) // webserverSettings.Dump("ss"); // webVirtualDirs.Dump("vd"); query { for name,sc in webserverSettings do join (vname,appRoot) in webVirtualDirs on ((name.ToString() + "/ROOT") = vname.ToString()) join (sname,path,appPoolId) in webVirtualDirSettings on (name.ToString()+ "/ROOT" = sname.ToString() ) select (appRoot,name,sc,path,appPoolId) }
详细执行代码:
type ScopeItem = | Scope of ManagementScope | Creation of string*bool*bool let private createAdvancedScope (path:string) requiresDomainSecurity requiresPacketSecurity = let scope = if requiresDomainSecurity then let conn = ConnectionOptions(Authority=sprintf "ntlmdomain:%s" Environment.UserDomainName) ManagementScope(path, conn) else ManagementScope(path, null) if requiresPacketSecurity then scope.Options.Authentication <- AuthenticationLevel.PacketPrivacy scope.Connect() scope let QueryWmiAdvanced (scopeInput: ScopeItem) query = let scope = match scopeInput with | Scope s -> s | Creation (path, requiresDomainSecurity, requiresPacketSecurity) -> createAdvancedScope path requiresDomainSecurity requiresPacketSecurity // createAdvancedScope path requiresDomainSecurity requiresPacketSecurity let query = new ObjectQuery(query) use searcher = new ManagementObjectSearcher(scope, query) use results = searcher.Get() results |> Seq.cast<ManagementObject> |> Array.ofSeq