Как получить информацию о приложении IIS через WMI
Вопрос
Как мне получить фактический путь к каталогу приложения IIS (виртуальной папки) с помощью WMI?
Решение
Использовать Скриптоматик V2 инструменты для просмотра большего количества подобных образцов:
On Error Resume NextConst wbemflagreturnimmedulty = & h10 const wbemflagforwardonly = & h20
arrcomputers = array ("*") для каждого StrComputer в arrcomputers wscript.echo wscript.echo "============================================================= ============ "Wscript.echo" Компьютер:"& strComputer wscript.echo" ======================================================================
Установить objwmiservice = getObject ("winmgmts: " & strComputer & " root microsoftiisv2") set colitems = objwmiservice.execquery ("select * from iiswebvirtualdir_iiswebvirtualdir", "wql", _ wbemflagretultifle + wbemflageblageblegelgemondimledimleblagelgiftilemblegemblegelagefortifle +
Для каждого objitem в 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, который должен возвращать тот же результат, что и ответ Исаламона.
От моего 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