Author Posts

December 30, 2015 at 9:22 am

Powershell and Machine.config help

I am very new to powershell and I need a quick hand if at all possible (I am sure this is a common sentence). I am writing a script that optimizes a server to become a webserver, i need to write to the machine.configs using powershell.

I have been trying to figure it out for over a month, lots of googling as well, I cant really find a solution, so I figured to come to the experts. Hopefully i can get good in powershell too and contribute at some point.

I have gotten incredibly far so far and have already done all of the optimizations and most of the powershell but am stuck on 1 part in the script

1. I need to get how many cpu cores the machine has
2. Once i have how many cores the machine has, i need to write to the machine.config some values.



I need to write

processModel maxWorkerThreads="370" maxIoThreads="370" minWorkerThreads="50" minIoThreads="50"
httpRuntime minFreeThreads="90" minLocalRequestFreeThreads="80"

This would overwrite the already present value listed below

processModel autoConfig="true"

Aside from writing that line there (which I cant figure out how to do), I need to multiply the minfreethreads by the number of CPU cores and write that value in the place of the 90 and the same for minLocalRequestFreeThreads 80

So for example, if the computation sees 2 cores it would write the following lines

processModel maxWorkerThreads="370" maxIoThreads="370" minWorkerThreads="50" minIoThreads="50"
httpRuntime minFreeThreads="180" minLocalRequestFreeThreads="160"

after that, I need to add
add address = "*" maxconnection = "200" 

As before, then replace the 200 with the multiplied values of the cpu cores and the 200. I hope that's not too much to ask, I don't know how to write to xml files, and then also multiply the cores and take that value and add it there?

so it would like this
add address = "*" maxconnection = "400" 

Can anyone give me a hand?

December 30, 2015 at 12:20 pm

Get-WmiObject win32_processor | select deviceid,NumberOfCores | ft -autosize

December 30, 2015 at 12:30 pm

Thank you Onur, Thank you so much for your input. I have been able to find that, but that lists the number of cores, which is great to have, but I need to know how to multiply that number of cores then add it to the strings above in the machine.conf and of course the other strings.