Advertisement
Dennisaa

AddRebecca

Sep 10th, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # If the id 103 does not exist in the XML file, create it as the key, and the firstName value
  2. $xmlFile = "c:\temp\students.xml"
  3. $xml = [xml] (get-content $xmlFile)
  4. $id = "103"
  5.  
  6. $found = ($xml.students.student | Where-Object {$_.id -eq $id})
  7. if ($found -eq $null) {
  8.     $newStudentXml = $xml.students.AppendChild($xml.CreateElement("student"))
  9.     $newStudentXml.SetAttribute("id",$id)
  10.     $newStudentXml.SetAttribute("firstName","Rebecca")
  11. }
  12. $xml.Save($xmlFile);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement