Applying the answer to my previous question How to expand file content with powershell
I stumbled upon a fatal error when trying to expand this :
test.js:
<script type="text/javascript">
$('.mylink').click(function(event) {
var hash = $(this).attr("href");
});
// $var
</script>
test.ps1
$test = get-content -raw test.html
$var = "test"
# Write to output file using UTF-8 encoding *without a BOM*.
[IO.File]::WriteAllText(
"$PWD/out.html",
$ExecutionContext.InvokeCommand.ExpandString($test)
)
$is a special symbol in PS and$()denotes an inlined expression so you'll need to escape it before expansion:expandString(($test -replace '\$\(', '`$('))$(which cannot be a part of an identifier. However, if you use PowerShell's$()then it's a problem that would require a smarter replacement algorithm to differentiate between jQuery and PS.