Код ниже работает с созданием нового файла, добавлением необходимых записей; однако, он стирает другие xml записи вместо того, чтобы просто обновлять те, которые нужно коснуться. Я не хочу, чтобы другие записи xml исчезали, и мне нужно повторно вводить информацию. Есть ли в powershell команда, которая обновляет только те записи, которые нужно обновить, и не затрагивает остальные записи xml?
XML:
<config description="Personal Settings">
<system description="Computer Information">
<Property ComputerName="" />
<Property UserName="" />
<Property Room="112" />
</system>
<Applications description="Application Settings">
<Property Name="Browser">Firefox</Property>
<Property Name="PDF">Acrobat</Property>
</Applications>
<Ownership>
<Property Organization="" />
<Division></Division>
<!-- The subdivision that the workstation belongs to (i.e. Classroom and Lab Computing) -->
<Subdivision>
</Subdivision>
<!-- The Group or area that the workstation belongs to (i.e. University Services) -->
<Group>Staff</Group>
<!-- The Budget number the workstation was purchased with -->
<BudgetID>
</BudgetID>
<!-- The purchase date -->
<FY>2017-2018</FY>
<PurchaseDate></PurchaseDate>
<LifeCycleDate></LifeCycleDate>
<!-- The ticket or service desk number associated with the original request for this workstation -->
<OriginalRequestID>
</OriginalRequestID>
</Ownership>
<Location>
<!-- The campus where the workstation primarily is located -->
<Campus>
</Campus>
<!-- The building where workstation is primarily located -->
<Building></Building>
<!-- The room number or name where workstation is primarily located -->
<Room></Room>
<!-- The address where the workstation is primarily located (useful if it's not at a Penn State campus) -->
<Address>
<Street></Street>
<City></City>
<State></State>
<ZipCode></ZipCode>
</Address>
</Location>
<LOGS description="Log TimeStamp">
<Property Time="03/11/2020 11:43:40" />
</LOGS>
</config>
Сценарий Powershell: # Создание нового XML файла с узлом config root [System. XML .XMLDocument] $ oXMLDocument = Система новых объектов. XML .XMLDocument
# New Node
[System.XML.XMLElement]$oXMLRoot=$oXMLDocument.CreateElement("config")
# Append as child to an existing node
$oXMLDocument.appendChild($oXMLRoot)
# Add a Attribute
$oXMLRoot.SetAttribute("description","Personal Settings")
[System.XML.XMLElement]$oXMLSystem=$oXMLRoot.appendChild($oXMLDocument.CreateElement("system"))
$oXMLSystem.SetAttribute("description","Computer Information")
#
#
[System.XML.XMLElement]$oXMLProperty=$oXMLSystem.appendChild($oXMLDocument.CreateElement("Property"))
$oXMLProperty.SetAttribute("ComputerName",$env:computername)
#
[System.XML.XMLElement]$oXMLProperty=$oXMLSystem.appendChild($oXMLDocument.CreateElement("Property"))
$ oXMLProperty.SetAttribute ("UserName", "Robert") # [System. XML .XMLElement] $ oXMLProperty = $ oXMLSystem.appendChild ($ oXMLDocument.CreateElement ("Свойство")) $ oXMLProperty.SetAttribute "(Room Room) 112 ") # [System. XML .XMLElement] $ oXMLApplications = $ o XMLRoot .appendChild ($ oXMLDocument.CreateElement (" Applications ")) $ oXMLApplications.SetAttribute (" description "," Настройки приложения ") . /Property[@Name="Browser"]').InnerText = "Firefox" # # [System. XML .XM LElement] $ oXMLProperty = $ oXMLApplications.appendChild ($ oXMLDocument.CreateElement ("Property")) $ oXMLProperty.SetAttribute ("Имя", "PDF") $ oXMLProperty.SelectSingleNode ('// Свойство [@ Name = "PDF]] ') .InnerText = "Acrobat" # [System. XML .XMLElement] $ oXMLLogs = $ o XMLRoot .appendChild ($ oXMLDocument.CreateElement ("LOGS")) $ oXMLLogs.SetAttribute ("description") , "Log TimeStamp") # [System. XML .XMLElement] $ oXMLProperty = $ oXMLLogs.appendChild ($ oXMLDocument.CreateElement ("Свойство")) $ Date = Get-Date $ oXMLProperty.SetAttribute ("Time", $ Дата) # # Сохранить файл $ oXMLDocument.Save ("c: \ Windows \ settings \ config. xml")