Writting to Machine.config using Powershell assistance required

This topic contains 2 replies, has 2 voices, and was last updated by  Iggy Castillo 1 year, 9 months ago.

  • Author
    Posts
  • #33382

    Iggy Castillo
    Participant

    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.

    Under

    system.web

    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

    system.net
    connectionManagement
    add address = "*" maxconnection = "200" 
    /connectionManagement
    /system.net

    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

    system.net
    connectionManagement
    add address = "*" maxconnection = "400" 
    /connectionManagement
    /system.net

    Can anyone give me a hand?

  • #33386

    Onur Kocaman
    Participant

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

  • #33388

    Iggy Castillo
    Participant

    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.

You must be logged in to reply to this topic.