title: Need help in updating (windows unattend.xml) xml file with powershell
body: <p>Here's my XML file: I would prefer to read the xml and then modify the computername to say newcompname and write it back to file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;unattend xmlns="urn:schemas-microsoft-com:unattend"&gt;
  &lt;servicing&gt;
  &lt;/servicing&gt;
  &lt;settings pass="specialize"&gt;
  &lt;component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;ComputerName&gt;testserver007&lt;/ComputerName&gt;
  &lt;RegisteredOrganization&gt;MyOrganization&lt;/RegisteredOrganization&gt;
  &lt;RegisteredOwner&gt;Admin&lt;/RegisteredOwner&gt;
  &lt;ShowWindowsLive&gt;false&lt;/ShowWindowsLive&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;fDenyTSConnections&gt;false&lt;/fDenyTSConnections&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;UserAuthentication&gt;1&lt;/UserAuthentication&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-TCPIP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" 
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;Interfaces&gt;
  &lt;Interface wcm:action="add"&gt;
  &lt;Ipv4Settings&gt;
  &lt;DhcpEnabled&gt;false&lt;/DhcpEnabled&gt;
  &lt;RouterDiscoveryEnabled&gt;false&lt;/RouterDiscoveryEnabled&gt;
  &lt;Metric&gt;10&lt;/Metric&gt;
  &lt;/Ipv4Settings&gt;
  &lt;Identifier&gt;Local Area Connection&lt;/Identifier&gt;
  &lt;Routes&gt;
  &lt;Route wcm:action="add"&gt;
  &lt;Identifier&gt;1&lt;/Identifier&gt;
  &lt;Metric&gt;10&lt;/Metric&gt;
  &lt;NextHopAddress&gt;192.168.2.247&lt;/NextHopAddress&gt;
  &lt;Prefix&gt;0.0.0.0/0&lt;/Prefix&gt;
  &lt;/Route&gt;
  &lt;/Routes&gt;
  &lt;UnicastIpAddresses&gt;
  &lt;IpAddress wcm:action="add" wcm:keyValue="1"&gt;192.168.2.101/24&lt;/IpAddress&gt;
  &lt;/UnicastIpAddresses&gt;
  &lt;/Interface&gt;
  &lt;/Interfaces&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-DNS-Client" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" 
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;Interfaces&gt;
  &lt;Interface wcm:action="add"&gt;
  &lt;DNSServerSearchOrder&gt;
  &lt;IpAddress wcm:action="add" wcm:keyValue="1"&gt;192.168.2.75&lt;/IpAddress&gt;
  &lt;IpAddress wcm:action="add" wcm:keyValue="2"&gt;192.168.2.76&lt;/IpAddress&gt;
  &lt;/DNSServerSearchOrder&gt;
  &lt;Identifier&gt;Local Area Connection&lt;/Identifier&gt;
  &lt;EnableAdapterDomainNameRegistration&gt;true&lt;/EnableAdapterDomainNameRegistration&gt;
  &lt;DisableDynamicUpdate&gt;false&lt;/DisableDynamicUpdate&gt;
  &lt;/Interface&gt;
  &lt;/Interfaces&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" 
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;DoNotOpenInitialConfigurationTasksAtLogon&gt;true&lt;/DoNotOpenInitialConfigurationTasksAtLogon&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" 
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;DoNotOpenServerManagerAtLogon&gt;true&lt;/DoNotOpenServerManagerAtLogon&gt;
  &lt;/component&gt;
  &lt;/settings&gt;
  &lt;settings pass="oobeSystem"&gt;
  &lt;component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" 
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;InputLocale&gt;0809:00000809&lt;/InputLocale&gt;
  &lt;SystemLocale&gt;en-GB&lt;/SystemLocale&gt;
  &lt;UILanguage&gt;en-US&lt;/UILanguage&gt;
  &lt;UserLocale&gt;en-GB&lt;/UserLocale&gt;
  &lt;/component&gt;
  &lt;component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" 
  xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;AutoLogon&gt;
  &lt;Password&gt;
  &lt;Value&gt;RgBvAG4ANgBIADAAbQBlAFAAYQBzAHMAdwBvAHIAZAA=&lt;/Value&gt;
  &lt;PlainText&gt;false&lt;/PlainText&gt;
  &lt;/Password&gt;
  &lt;Domain&gt;testserver007&lt;/Domain&gt;
  &lt;Enabled&gt;true&lt;/Enabled&gt;
  &lt;LogonCount&gt;5&lt;/LogonCount&gt;
  &lt;Username&gt;Administrator&lt;/Username&gt;
  &lt;/AutoLogon&gt;
  &lt;FirstLogonCommands&gt;
  &lt;SynchronousCommand&gt;
  &lt;Order&gt;1&lt;/Order&gt;
  &lt;!-- Post Build Script 1 --&gt;
  &lt;CommandLine&gt;cmd.exe /C C:\BuildScripts\firsttest.cmd&lt;/CommandLine&gt;
  &lt;/SynchronousCommand&gt;
  &lt;/FirstLogonCommands&gt;
  &lt;Display&gt;
  &lt;ColorDepth&gt;32&lt;/ColorDepth&gt;
  &lt;HorizontalResolution&gt;1024&lt;/HorizontalResolution&gt;
  &lt;VerticalResolution&gt;768&lt;/VerticalResolution&gt;
  &lt;/Display&gt;
  &lt;OOBE&gt;
  &lt;HideEULAPage&gt;true&lt;/HideEULAPage&gt;
  &lt;ProtectYourPC&gt;3&lt;/ProtectYourPC&gt;
  &lt;NetworkLocation&gt;Other&lt;/NetworkLocation&gt;
  &lt;/OOBE&gt;
  &lt;UserAccounts&gt;
  &lt;AdministratorPassword&gt;
  &lt;Value&gt;RgBvAG4ANgBIADAAbQBlAEEAZABtAGkAbgBpAHMAdAByAGEAdABvAHIAUABhAHMAcwB3AG8AcgBkAA==&lt;/Value&gt;
  &lt;PlainText&gt;false&lt;/PlainText&gt;
  &lt;/AdministratorPassword&gt;
  &lt;/UserAccounts&gt;
  &lt;RegisteredOrganization&gt;MyOrganization&lt;/RegisteredOrganization&gt;
  &lt;RegisteredOwner&gt;Admin&lt;/RegisteredOwner&gt;
  &lt;TimeZone&gt;GMT Standard Time&lt;/TimeZone&gt;
  &lt;LogonCommands&gt;
  &lt;AsynchronousCommand wcm:action="add"&gt;
  &lt;CommandLine&gt;cmd.exe /C C:\Scripts\test.cmd&lt;/CommandLine&gt;
  &lt;Description&gt;test command&lt;/Description&gt;
  &lt;Order&gt;2&lt;/Order&gt;
  &lt;RequiresUserInput&gt;true&lt;/RequiresUserInput&gt;
  &lt;/AsynchronousCommand&gt;
  &lt;/LogonCommands&gt;
  &lt;/component&gt;
  &lt;/settings&gt;
  &lt;cpi:offlineImage cpi:source="catalog:d:/win2008r2instfiles/sources/install_windows server 2008 r2 serverstandard.clg" xmlns:cpi="urn:schemas-microsoft-com:cpi" /&gt;
  &lt;/unattend&gt;
  </code></pre>