Performance web管理vs WMI查询web目录属性性能问题
我一直在为IIS构建一个服务器差异脚本,我发现使用web管理模块比WMI获取相同信息的速度要慢得多。我在2003年的日落项目中首先构建了WMI模块,但我发现当我开始使用IIS7方法时,速度非常慢 处理时间——IIS7:348.988,IIS6:10.309(秒) 最大的时间损失是检索webapp下每个目录的属性,每10个目录大约需要5秒或每个目录2秒!WMI可以在10秒内完成整个网站Performance web管理vs WMI查询web目录属性性能问题,performance,powershell,iis,wmi,iis-metabase,Performance,Powershell,Iis,Wmi,Iis Metabase,我一直在为IIS构建一个服务器差异脚本,我发现使用web管理模块比WMI获取相同信息的速度要慢得多。我在2003年的日落项目中首先构建了WMI模块,但我发现当我开始使用IIS7方法时,速度非常慢 处理时间——IIS7:348.988,IIS6:10.309(秒) 最大的时间损失是检索webapp下每个目录的属性,每10个目录大约需要5秒或每个目录2秒!WMI可以在10秒内完成整个网站 . C:\scripts\PS\bits\Get-SelectPropertyArray.ps1 # a hel
. C:\scripts\PS\bits\Get-SelectPropertyArray.ps1
# a helper file that converts a field, alias and expression into a selectable property
. C:\scripts\PS\bits\Get-FlagAsList.ps1
# a helper function to tag a series of boolean properties and convert them into a single csv string with the "name" of the flags turned on
function Get-IIS7ConfigForPSPath
{
[CmdletBinding()]
param (
[string]$PSPath
)
$propsToSelect = @("Name","Path","PSPath")
<# Check the FlagValue datatype because when not configured it returns an object instead of an empty string! #>
$propsToSelect += Get-SelectPropertyArraySet "." "Handlers_AccessFlags" {
$flagValue = (get-webconfigurationProperty -filter /system.webServer/handlers -Name AccessPolicy -PSPath $PSPath)
if ($flagValue.GetType().Name -eq "ConfigurationAttribute")
{ "" } else {$flagValue}
}
<# Check the FlagValue datatype because when not configured it returns an object instead of an empty string! #>
$propsToSelect += Get-SelectPropertyArraySet "." "Access_sslFlags" {
$flagValue = (get-webconfigurationProperty -filter /system.webServer/security/access -Name sslFlags -PSPath $PSPath)
if ($flagValue.GetType().Name -eq "ConfigurationAttribute")
{ "" } else {$flagValue}
}
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_AppAllowClientDebug" {
(get-webconfigurationProperty -filter /system.webServer/asp -Name AppAllowClientDebug -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_AppAllowDebugging" {
(get-webconfigurationProperty -filter /system.webServer/asp -Name AppAllowDebugging -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_limits_bufferingLimit" {
(get-webconfigurationProperty -filter /system.webServer/asp/limits -Name bufferingLimit -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_EnableParentPaths " {
(get-webconfigurationProperty -filter /system.webServer/asp -Name EnableParentPaths -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_limits_queueTimeout" {
(get-webconfigurationProperty -filter /system.webServer/asp/limits -Name queueTimeout -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_limits_requestQueueMax" {
(get-webconfigurationProperty -filter /system.webServer/asp/limits -Name requestQueueMax -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "Asp_limits_scriptTimeout" {
(get-webconfigurationProperty -filter /system.webServer/asp/limits -Name scriptTimeout -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "security_auth_Anonymous" {
(get-webconfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -Name Enabled -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "security_auth_Basic" {
(get-webconfigurationProperty -filter /system.webServer/security/authentication/basicAuthentication -name enabled -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "web_limits_ConnectionTimeout" {
(get-webconfigurationProperty -filter /system.applicationHost/webLimits -Name ConnectionTimeout -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "HttpCompression_DoDynamicCompression" {
(get-webconfigurationProperty -filter /system.webServer/httpCompression/scheme -Name DoDynamicCompression -PSPath $PSPath).Value }
$propsToSelect += Get-SelectPropertyArraySet "." "HttpCompression_DoStaticCompression" {
(get-webconfigurationProperty -filter /system.webServer/httpCompression/scheme -Name DoStaticCompression -PSPath $PSPath).Value }
# convert property array sets into selectable properties
$props = $propsToSelect | Get-SelectPropertyArray2
# retrieve the properties, no pipeline input is required as we are doing all the logic in the script blocks
$config = Get-Item $PSPath | select -Property $props
if ( !($config.Path) -or $config.Path -eq $null)
{
$config.Path = $PSPath
}
return $config
}
Get-IIS7ConfigForPSPath -PSPath ("IIS:Sites\{0}" -f $iis7Site.name)
通过比较,这里是我的WMI请求:
$start = [System.DateTime]::Now
$numanalyzed = 0
$iis6VWebDirConfig = @()
foreach ($vdir in $iis6VirDirConfig)
{
#retrieve the desired fields for the web directory
$iis6VWebDirConfig += Get-WmiObject -class IIsWebDirectorySetting -Namespace "root/MicrosoftIISv2" `
-Filter ("Name like '"+$vdir.Name+"%'") |
select -Property $props
$numAnalyzed++
$end = [System.DateTime]::Now
$timeSoFar = (NEW-TIMESPAN -Start $Start -End $End).TotalSeconds
$timeremaining = ($iis6VirDirConfig.Count - $numAnalyzed) * ($timeSoFar / $numanalyzed)
"Analyzed {0} so far... took {1} seconds, remaining time {2} seconds" -f $numanalyzed,$timeSoFar,$timeremaining | write-host
"Current Folder: {0}" -f $folder.FullName | Write-Host
}
"Web Directories Found: {0}" -f $iis6VWebDirConfig.Count | Write-Host
$end = [System.DateTime]::Now
"Processed web dirs: {0} took {1} seconds" -f $iis7VWebDirConfig.Count,(NEW-TIMESPAN -Start $Start -End $End).TotalSeconds | write-host | Write-Host
有谁知道从IIS7 metabase获取所有这些属性的更好方法吗?从长远来看,我担心WMI的正向支持,我发现WMI检索时有1或2个属性不正确。为什么您担心WMI的正向支持?如果此处有任何更改,我认为使用IIS元数据库是长期的正确方法。我还发现WMI对于其中一个超时属性是不准确的。
$start = [System.DateTime]::Now
$numanalyzed = 0
$iis6VWebDirConfig = @()
foreach ($vdir in $iis6VirDirConfig)
{
#retrieve the desired fields for the web directory
$iis6VWebDirConfig += Get-WmiObject -class IIsWebDirectorySetting -Namespace "root/MicrosoftIISv2" `
-Filter ("Name like '"+$vdir.Name+"%'") |
select -Property $props
$numAnalyzed++
$end = [System.DateTime]::Now
$timeSoFar = (NEW-TIMESPAN -Start $Start -End $End).TotalSeconds
$timeremaining = ($iis6VirDirConfig.Count - $numAnalyzed) * ($timeSoFar / $numanalyzed)
"Analyzed {0} so far... took {1} seconds, remaining time {2} seconds" -f $numanalyzed,$timeSoFar,$timeremaining | write-host
"Current Folder: {0}" -f $folder.FullName | Write-Host
}
"Web Directories Found: {0}" -f $iis6VWebDirConfig.Count | Write-Host
$end = [System.DateTime]::Now
"Processed web dirs: {0} took {1} seconds" -f $iis7VWebDirConfig.Count,(NEW-TIMESPAN -Start $Start -End $End).TotalSeconds | write-host | Write-Host