html - In Powershell Use -replace or .replace To Change TD value to a Link -


I'm trying to prepare the HTML report of the data collected in PowerShell. I want to get the HTML link for more specific information. Specifically, the first column contains the name of the virtual machine, but it is not particularly important, I am trying to change the value of the name with a link. ($ I = 1; $ i -le $ xml.table.tr.Count-1; $ i ++) {$ xml .table.tr [$ i] for

  Td [0] .replace ($ xml.table.tr [$ i] .td [0], "& lt; a href =` http: // stackoverflow.com` "& gt; MyLink & lt; / a & Gt; "}} $ file = join-path C: \ users \ myname \ document" VMSpecs.html "ConvertTo-HTML -Title" VM Specs "` -CssUri C: \ users \ myname \ document \ style .css ` - Body $ ($ xml.InnerXml) | Out-File $ File Avatar-item $ file  

Based on the output, $ xml.table.tr is worth [$ i] .td [0] is being replaced with links Information but not permanent when the file is written on HTML then the link information is nowhere, and the original The value is still in TDL

Therefore, the big picture, I would like to know how to add a link html -fragment to a particular place, any samples or resources are heavily compelled.

Both. What would you like to do, reassign the result:

 For  ($ i = 1; $ I -le $ xml.table.tr.Count-1; $ I ++) {$ xml .table.tr [$ i] .td [0] = $ xml.table.tr [$ i] .td [0] .replace ($ xml.table.tr [$ i] .td [0], "and  & gt; myLink & lt; / a & gt;"}}  

However, in this particular case, it does not seem that there is any need for everyone's place. Since you are changing the entire contents of TD, just specify it directly:

  For ($ i = 1; $ i -le $ xml.table.tr.Count-1; $ I ++) {$ xml.table.tr [$ i] .td [0] = "& lt; a href = `" Http: // stackoverflow.com` "& gt; myLink & lt; / a & gt;"}  

Instead of telling a node, It has been forgotten about reflecting the question. It seems that when you get a special element above, PowerShell is converting it into a string, so you are not actually updating the node instead it Try:

 For  ($ i = 1; $ i -le $ xml.table.tr.Count-1; $ i ++) {($ xml.table.tr [$ I] Choose .GetElementsByTagName ("td") -Object -First 1). "# Text" = "& lt; a href = '' http: // stackoverflow.com`" & gt; myLink & lt; / a & gt; "}  

" # Text "property may be different, I'm not sure. I did a test with a very simple HTML file, and as a result, by creating a gate-member at every level of the XML object, I found that this was the property I wanted to update.

$ I -le $ xml.table.tr.Count-1; $ I ++) {$ link = $ xml.CreateElement ("a") $ link.SetAttribute ("href", "http://stackoverflow.com ") $ Link.InnerText =" myLink "$ xml.table.tr [$ I] First child "#text" = "" $ xml.table.tr [$ i]. First Child .AppendChild ($ link)}


Comments