How to detect if a change has been made in a file, to skip to the next section


with help, have been able write below powershell script.  it works great, need prepair if's.  what if script started again?  currently, if script run again, after has been run, add of these lines, redundant , possibly cause issue.

how can make if when portion of script run, detects change in machine.config file goes next instance.  if next instance has change, after detecting instances, has seen have changes, skips them , runs next line, has nothing updating machine.config?

i new powershell, not sure here.

here script far

"updating framework64 - v4.0.30319"
$numberofcores = get-wmiobject -class win32_processor | measure-object numberofcores -sum | select-object -expandproperty sum
$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")

"updating framework64 - v2.0.50727"

$numberofcores = get-wmiobject -class win32_processor | measure-object numberofcores -sum | select-object -expandproperty sum
$path = "c:\windows\microsoft.net\framework64\v2.0.50727\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\v2.0.50727\config\machine.config")

add version entry confit file , update it.  there no other way know file has been updated.

add comment line beginning of file this:

<!-- edited 10-12-2016 -->

this can created:

$cmnt = $machineconfig.createcomment(' edited 10-12-2016 ')
$machineconfig.insertbefore($cmnt,$machineconfig.childnodes[1])


\_(ツ)_/




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file