【发布时间】:2015-04-14 22:25:32
【问题描述】:
我创建了一系列函数,这些函数基本上收集了有关站点的所有 IIS 配置,当在本地服务器上运行时,它可以毫无问题地执行(尽管速度很慢)但是当我在 中使用invoke-command 远程运行它们时PowerShell 2 它运行并神秘地停止了大约 15-20 秒的过程。它通常会因相同的请求而停止,但并非总是如此。在本地执行的相同命令没有任何问题。没有引发异常,它只是无限期挂起。
如有必要,我可以发布代码,但它有几百行,所以我更希望获得有关如何调查此类问题或是否有人遇到类似问题的指导。
Comparing IISConfig between [targetserver] and localhost.
Checking Installed IIS version on [targetserver]:
IIS major version : 7
IIS minor version : 5
IIS7+ detected, using WebAdmin module and IIS metabase
Name Value
---- -----
name Default Web Site
id 1
serverAutoStart True
state 1
Site Configuration:
Name Path PSPath Handlers_Ac Access_sslF Asp_AppAllo Asp_AppAllo Asp_limits_ Asp_EnableP Asp_limits_
cessFlags lags wClientDebu wDebugging bufferingLi arentPaths queueTimeou
g mit t
---- ---- ------ ----------- ----------- ----------- ----------- ----------- ----------- -----------
Default ... IIS:Site... WebAdmin... Read,Script False False 25000000 True 00:00:00
WebApp VDir: /MyApp, App Pool: MyApp
App pool Configuration:
AppPoolID Enable32Bit managedPipe managedRunt AppPoolName AppPoolAuto processMode processMode processMode recycling_l
AppOnWin64 lineMode imeVersion Start l_idleTimeo l_identityT l_UserName ogEventOnRe
ut ype cycle
--------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
False Classic v2.0 MyApp True 00:20:00 LocalSer... Time,Req...
Analyzing web directories for /MyApp, this could take a while....
Initial Collection Completed, found 141... took 0.9516122 seconds
0 C:\inetpub\wwwroot\MyApp\Core
1 C:\inetpub\wwwroot\MyApp\Core\AdminTools
2 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Cache
3 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Extra
4 C:\inetpub\wwwroot\MyApp\Core\AdminTools\HTTPPostTest
5 C:\inetpub\wwwroot\MyApp\Core\AdminTools\IISAdmin
6 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Profiling
7 C:\inetpub\wwwroot\MyApp\Core\AdminTools\RecordTestData
8 C:\inetpub\wwwroot\MyApp\Core\AdminTools\ScrambleTest
9 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Sessions
Analyzed 10 so far... took 6.7236862 seconds, remaining time 88.08028922 seconds
Current Folder: C:\inetpub\wwwroot\MyApp\Core\AdminTools\Sessions
10 C:\inetpub\wwwroot\MyApp\Core\AdminTools\SoapTest
11 C:\inetpub\wwwroot\MyApp\Core\AdminTools\StaticContent
有时它会达到 15 左右。我尝试从我的笔记本电脑和从一台服务器到另一台服务器,行为是相同的。
这是挂起的循环:
$start = [System.DateTime]::Now
$numanalyzed = 0
if ($true) #skip to test
{
# loop through all physical folders as it is much faster
foreach ($folder in $folders)
{
write-host $numanalyzed $folder.fullname
#figure out the virtual path to the folder
$iis7vwebfolderpath = $folder.FullName.Replace($iis7webapp.PhysicalPath, $iis7VDirWebApppath)
#Get-item $iis7vwebfolderpath | gm
$iis7VWebDirConfigItem = Get-LNOSIIS7ConfigForPSPath -PSPath $iis7vwebfolderpath
# add new item to list
$iis7VWebDirConfig += $iis7VWebDirConfigItem
# increment counter and report out progress every 10
$numAnalyzed++
if ($numanalyzed % 10 -eq 0)
{
$end = [System.DateTime]::Now
$timeSoFar = (NEW-TIMESPAN –Start $Start –End $End).TotalSeconds
$timeremaining = ($folders.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
}
}
}
$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
我遇到性能问题的函数,我有一个单独的问题,但这篇文章有该函数的源代码:
web-administration vs WMI to query web directory properties performance problems
【问题讨论】:
-
我假设您消除了任何网络或通信问题。您是否尝试过单步执行脚本以找出它到底挂在哪里?我的意思是在哪个操作期间。然后尝试手动执行这些操作。
-
我会试试你帖子@user4317867中的提示。
-
@slybloty 是的,我已经排除了网络/通信问题,因为它是 100% 可重现的,而且我去了同一子网上的服务器。它发生在任何远程主机上,无论我使用哪一个都没有关系,除非我们网络上的每台服务器都对我们网络上的每台其他服务器都存在网络问题,而不是网络。当我在服务器上本地运行整个脚本时,它工作正常。它正在经历一个循环,我写出我在循环中的位置,它在 10-20 次迭代后停止。我将编辑问题以包含循环代码块及其在循环中调用的函数
标签: powershell-2.0 freeze invoke-command