Just a quick post regarding adding comments to XML files in powershell. ie. Build versions in config files etc.
param([string]$configfile="C:\Users\mh0030\Documents\PowerShell\CommentTestFile.xml", [string]$comment="My default comment")
$doc = [xml](get-content $configfile)
$root = $doc.SelectSingleNode("/MyRoot")
$comment = $doc.CreateComment($comment)
$doc.InsertBefore($comment,$root)
$outFile = (Split-Path -Parent $configfile) + "\outfile.xml"
$doc.save($outFile)
The two important parts are; the navigator element, in this case $root as selected by "/MyRoot" and the other part is how you want to insert the comment. InsertAfter, InsertBefore, AppendChild.
Michael Høtoft
0df3b673-01ea-4e27-92fa-c8d1eb05075b|0|.0
Sharepoint Server
PowerShell, XML