我已经在这个剧本上工作了很长一段时间,但不得不停下来,因为我无法花时间在它上面。我现在可以更多地关注它,它似乎不能正常工作,希望我能得到一些帮助。
此脚本旨在首先删除machine.config中的一个部分,即ProcessModel autoConfig =" true" />行
$node = $machineConfig.SelectNodes("/configuration/system.web")
$node.RemoveChild(($node.SelectSingleNode("processModel"))) | Out-Null
然后它将以下
写回processModel<system.web>
<processModel maxWorkerThreads="370" maxIoThreads="370" minWorkerThreads="50" minIoThreads="50"/>
<httpRuntime minFreeThreads="90" minLocalRequestFreeThreads="80"/>
然后在这里它变得有点棘手,我希望它能够通过虚拟机上的CPU内核数量来复制90和80。例如,如果机器有4个核心,它将读取
<system.web>
<processModel maxWorkerThreads="370" maxIoThreads="370" minWorkerThreads="50" minIoThreads="50"/>
<httpRuntime minFreeThreads="360" minLocalRequestFreeThreads="320"/>
之后,在文件底部,我希望它添加以下行
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "200" />
</connectionManagement>
</system.net>
与前一个一样,我需要将200乘以虚拟机的CPU核心数。因此,例如,如果机器有4个核心,则会读取
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "800" />
</connectionManagement>
</system.net>
我所做的代码是它编写了processModel部分,但它并没有为我增加,它似乎没有添加maxconnection数字,只留下一个空格。这是我到目前为止的代码
$numberOfCores = Get-WmiObject -class win32_processor numberOfCores | Select-Object -ExpandProperty numberOfCores
$path = "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config"
[xml]$machineConfig = Get-Content $path
$node = $machineConfig.SelectNodes("/configuration/system.web")
$node.RemoveChild(($node.SelectSingleNode("processModel"))) | Out-Null
$processModelxml = $machineConfig.CreateElement("processModel")
$processModelxml.setAttribute("maxWorkerThreads",370)
$processModelxml.setAttribute("maxWorkerThreads",370)
$processModelxml.setAttribute("maxIoThreads",370)
$processModelxml.setAttribute("minWorkerThreads",50)
$processModelxml.setAttribute("minIoThreads",50)
$node.AppendChild($processModelxml) | Out-Null
$httpRuntimexml = $machineConfig.CreateElement("httpRuntime")
$httpRuntimexml.setAttribute("minFreeThreads",90 * $numberOfCores)
$httpRuntimexml.setAttribute("minLocalRequestFreeThreads",80 * $numberOfCores)
$node.AppendChild($httpRuntimexml) | Out-Null
[xml]$systemnetxml = @"
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "$(200 * $numberOfCores)" />
</connectionManagement>
</system.net>
"@
$machineConfig.configuration.AppendChild($machineConfig.ImportNode($systemnetxml."system.net",$true)) | Out-Null
$machineConfig.Save("c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config")
近一年来我一直在努力解决这个问题,我不得不离开它,然后回到它,我发现它不起作用。
出现以下错误
此外,它会扭曲machine.config文件的原始格式。 Machine.config位于Windows Server 2012 R2文件系统中,因此如果您想在自己的计算机上测试该文件,请确保先备份该文件。我讨厌你弄乱自己的机器试图帮助我。
请提前帮助并谢谢。
答案 0 :(得分:2)
为什么不使用专门用于配置的类?
$numberOfCores = Get-WmiObject -class win32_processor numberOfCores | Select-Object -ExpandProperty numberOfCores
$machineConfig = [System.Configuration.ConfigurationManager]::OpenMachineConfiguration()
$processModel = $machineConfig.SectionGroups['system.web'].ProcessModel
$processModel.SectionInformation.RevertToParent()
$processModel.MaxWorkerThreads = 370
$processModel.MaxIOThreads = 370
$processModel.MinWorkerThreads = 50
$processModel.MinIOThreads = 50
$httpRuntime = $machineConfig.SectionGroups['system.web'].HttpRuntime
$httpRuntime.MinFreeThreads = 90 * $numberOfCores
$httpRuntime.MinLocalRequestFreeThreads = 80 * $numberOfCores
$connectionManagement = $machineConfig.SectionGroups['system.net'].ConnectionManagement
$connectionManagement.ConnectionManagement.Add((New-Object System.Net.Configuration.ConnectionManagementElement *, (200 * $numberOfCores)))
$machineConfig.Save()