IIS 用のサーバー diff スクリプトを作成していますが、Web 管理モジュールを使用すると、同じ情報を取得するのに WMI よりも大幅に時間がかかることがわかりました。私は 2003 年のサンセット プロジェクトに取り組んでいるので、最初に WMI モジュールをビルドしましたが、IIS7 メソッドを使い始めたときに非常に遅いことがわかりました。
処理時間 -- IIS7: 348.988、IIS6: 10.309 (秒)
最大の時間の損失は、webapp の下の各ディレクトリのプロパティを取得することです。これには、10 個のディレクトリごとに最大 5 秒、またはそれぞれ 2 秒かかります! WMI は、Web サイト全体を 10 秒で処理できます。
. 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)
これは、仮想ディレクトリごとにこれを160回以上実行する必要があるため、私を殺しているものです:
Get-IIS7ConfigForPSPath -PSPath $iis7vwebfolderpath
比較すると、ここに私の 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 メタベースからこれらすべてのプロパティを取得するより良い方法を知っている人はいますか? 長い目で見れば、WMI の前方サポートについて懸念があります。WMI によって取得されたときに正しくないプロパティが 1 つまたは 2 つ見つかりました。