I am trying edit a HTML file in powershell, I want to remove the tag head and it contents and add CSS element style and it's contents to the HTML file. I am using Microsoft HTML document class to access HTML file. I am getting error The assignment expression is not valid at this line "$($($HTML.getElementsByTagName('head')).innerHTML) = $CssContent" in powershell
HTML file
<html xmlns:string="xalan://java.lang.String" xmlns:lxslt="http://xml.apache.org/xslt">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Summary</title>
<link rel="sheet" type="text/css" title="Style" href="sheet.css">
</head>
CSS content to be replaced in HTML file
body {
font:normal 68% verdana,arial,helvetica;
color:#000000;
}
table tr td, table tr th {
font-size: 68%;
}
powershell Script
#get contents of file
$Content = Get-Content 'test.html' -raw
$CssContent = Get-Content 'test.css' -raw
# Create HTML file Object
$HTML = New-Object -Com "HTMLFile"
$HTML.IHTMLDocument2_write($Content)
#Assign InnerHTML to CssContent
$($($HTML.getElementsByTagName('head')).innerHTML) = $CssContent
#the error i get is "The assignment expression is not valid at this line"
Get-Command -Name '*xml*'.innerHTMLmakes no sense. You would have to append astyleelement as child ofheadelement.