XML Attribute Update

I have an XML similar to this :

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
  <Format_Version>1.0</Format_Version>
  <Reporting>
  </Reporting>
  <Jobs>
        <!--<Job>
                <Name>SpaceCheck</Name>
                <Job_Type>SpaceCheck</Job_Type>
                <Schedule>
                    <Start_Time>0300</Start_Time>
                    <Frequency>24 hours</Frequency>
                    <Max_Run_Time_In_Seconds>10</Max_Run_Time_In_Seconds>
                </Schedule>
                <Parameters>
                    <Drive>C</Drive>
                    <Drive>D</Drive>
                </Parameters>
        </Job>
        <Job>
                <Name>CPUCheck</Name>
                <Job_Type>UsageMonitor</Job_Type>
                <Schedule>
                    <Frequency>3 minutes</Frequency>
                </Schedule>
                <Parameters>
                    <Threshold>90%</Threshold>
                    <Duration>10 minutes</Duration>
                </Parameters>
        </Job>
        <Job>
                <Name>overloaded CPUCheck</Name>
                <Job_Type>CPUcheck2</Job_Type>
                <Schedule>
                    <Frequency>3 minutes</Frequency>
                </Schedule>
                <Parameters>
                    <Threshold>80%</Threshold>
                    <Duration>50 minutes</Duration>
                </Parameters>
            </Job>-->
        <Job>
          <Name>Connection</Name>
          <Job_Type>Connectivity</Job_Type>
          <Schedule>
            <Start_Time>1900</Start_Time>
            <Frequency>1</Frequency>
            <Maximum_Runtime>30</Maximum_Runtime>
          </Schedule>
          <Parameters>
            <ToErrInHours>1</ToErrInHours>
            <Days>1</Days>
            <Threshold>70</Threshold>
          </Parameters>
        </Job>
      </Jobs>
    </Configuration>

I am trying to update the value of Start_Time from 1900 to 2300. The problem is the element getting updated but not the value. How can I resolve this.

tried to update – this way :

#Get the content of the Config File
$xdoc = [xml](Get-content "C:Program Files (x86)AlphaBetagamma.xml")
#Get the value of the Attribute key
$StartTime = $XDoc.SelectSingleNode("//Start_Time[1]")
echo $StartTime
# Set the attribute
$StartTime.SetAttribute("Start_Time", "2300")
$xdoc.Save('C:Program Files (x86)AlphaBetagamma.xml')
echo $StartTime


Source: .net

Leave a Reply