我创建了一系列函数,基本上收集了有关站点的所有IIS配置,当在本地服务器上运行时,它没有问题地执行(尽管速度缓慢),但是当我使用invoke-command in 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
发布于 2015-04-17 12:52:50
我想我可能已经发现了这个问题,我开始在脚本的其他部分出现一些奇怪的失败:
[SEVERNAME] Processing data from remote server SERVERNAME failed with the following error message: The WSMan provider host process did not return a proper response. A provider in the host process may have behaved improperly. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (SERVERNAME:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : 1726,PSSessionStateBroken和
Processing data for a remote command failed with the following error message: Not enough storage is available to complete this operation. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OperationStopped (System.Manageme...pressionSyncJob:PSInvokeExpressionSyncJob) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure这将引导我访问以下站点:http://www.gsx.com/blog/bid/83018/Troubleshooting-unknown-PowerShell-error-messages
下面的建议似乎已经解决了大部分问题,尽管我还有一些测试要做。
摘录自以下站点:
正如第一个错误消息所指定的,远程会话中出现了内存溢出。在远程服务器上打开一个PowerShell提示符,并使用以下方法显示winr的配置:
winrm get winrm/config/winrs检查"MaxMemoryPerShellMB“值。在Windows 2008 R2和Windows 7上,默认设置为150 MB。这是微软在Windows 2012和Windows 8到1024 MB中更改的内容。
为了解决这个问题,需要使用以下命令将值增加到至少512 MB:
winrm set winrm/config/winrs `@`{MaxMemoryPerShellMB=`"512`"`}发布于 2018-07-25 06:35:43
在我的例子中,由于空闲超时过期(调用运行了很长时间),我的PowerShell调用似乎冻结了。
将IdleTimeout值设置为足够长的持续时间解决了我的问题。
再次,使用
winrm get winrm/config/winrs并使用
winrm set winrm/config/winrs '@{IdleTimeout="18000000"}'发布于 2020-09-30 16:49:30
作为一个FYI,如果调用-命令总是挂起:
Invoke-Command -ComputerName XXXXX -ScriptBlock { Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion }https://stackoverflow.com/questions/29638446
复制相似问题