Using -f string format on get-content data in PowerShell

amandapanda

New Member
I've got an XML template I put in a txt file. I'd like to import it to a variable and use "-f" to input my data into the string. Something like:\[code\]$XMLtmplt = get-content C:\XMLtemplate.txt$XML = "$XMLtmplt" -f $objID $pageTitle $otherData$OneNoteObject.UpdatePageContent($XML)\[/code\]This works when the $XMLtmplt variable is set with a small string, but fails when I import a large string from a file. I'd rather not put a long XML string in my script; importing from a file is nice. My only work around thus far is to break up the data before and after the insertion point like:\[code\]$XML = "<All the first data>"$XML += $1stVariableToInsert$XML += "<more XML stuff>"$XML += $2ndVariableToInsert...$OneNoteObject.UpdatePageContent($XML)\[/code\]BTW, this is for building XML for the MS OneNote API, which I've found to be quite temperamental. The error codes are less than descriptive. A general "bad XML" doesn't help when you've got hundreds of lines of XML.Any ideas?
 
Back
Top