Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I edit an HTML tag using PowerShell?
    text
    copied!<p>I have created PS script that queries the Event Logs on my Servers then writes the info to a plain old html file. The problem being is the html file is just that, plian. What I want to do is add jquery's DataTables to it so that I can sort and organize it. </p> <p>Using the "ConvertTo-HTML -head" commandlet I can insert the code I need into the head of the document <em>before</em> the document is written. After the file is written I then need to open it and change to . </p> <p>The problem I'm having is when the script gets to the replace tag part, I get this error:</p> <blockquote> <p>Set-Content : The process cannot access the file C:\users\norm\Documents\eventlogs\2011\02\System\04\tc2.html' because it is being used by another process.</p> </blockquote> <p>I suspect that it is because the pipe used to open the file still has it open. So how do I close the file? or is there a better way of doing it?</p> <p>Thanks, Norm</p> <pre><code> # EventLog viewer # Head for the HTML document. Adds the CSS and JQuery DataTables to the document. $h = '&lt;head&gt; &lt;meta http-equiv="pragma" content="no-cache" /&gt;' $h = $h + '&lt;title&gt;Celeste EventLog Viewer&lt;/title&gt;' $h = $h + '&lt;link type="text/css" rel="stylesheet" href="css/demo_table_jui.css" /&gt;' $h = $h + '&lt;link type="text/css" rel="stylesheet" href="themes/base/jquery.ui.all.css" /&gt;' $h = $h + '&lt;link type="text/css" rel="stylesheet" href="css/stdcst.css" /&gt;' $h = $h + '&lt;script language="JavaScript" src="js/jquery.min.js"&gt;&lt;/script&gt;' $h = $h + '&lt;script language="JavaScript" src="js/jquery.dataTables.js"&gt;&lt;/script&gt;' $h = $h + '&lt;/head&gt;' $h = $h + '&lt;script type="text/javascript"&gt; $(document).ready(function() {$("#t1").dataTable( {"bJQueryUI": true,"sPaginationType": "full_numbers", "bInfo" : true } ); });&lt;/script&gt;' $ServerNames = "s1","s2","s3","s4","s5","s6","s7","s8","s9" $outdir = 'C:\users\norm\Documents\eventlogs\' $year = get-date -uformat "%Y" $month = get-date -uformat "%m" $day = get-date -uformat "%d" $count = $ServerNames.length # Get the length of ServerNames, iterate through x until x is greater than ServerNames for ($x=0; $x -lt $count; $x++) { # Before writing the file can begin the output directory needs to exsist. Test that it does, if not create it. if (( Test-Path -path $outdir$year\$month\System\$day\) -ne $True) { New-Item $outdir$year\$month\System\$day\ -type directory } if (( Test-Path -path $outdir$year\$month\Application\$day\) -ne $True) { New-Item $outdir$year\$month\Application\$day\ -type directory } echo "Getting System log from " $ServerNames[$x] #Query the System Event log and write it to an html file Get-EventLog -computername $ServerNames[$x] -LogName System | ConvertTo-HTML -head $h | Out-File -encoding utf8 $outdir$year\$month\System\$day\"$($ServerNames[$x]).html"; # Query the Aplication Event log and write it to an html file echo "Getting Application log from " $ServerNames[$x] Get-EventLog -computername $ServerNames[$x] -LogName Application | ConvertTo-HTML -head $h | Out-File -encoding utf8 $outdir$year\$month\Application\$day\"$($ServerNames[$x]).html"; } for ($x=0; $x -lt $count; $x++) { #Open the files and replace the table tag Get-Content $outdir$year\$month\System\$day\"$($ServerNames[$x]).html" | ForEach-Object { $_ -replace '&lt;table&gt;', '&lt;table id="t1"&gt;'} | Set-Content $outdir$year\$month\"$($ServerNames[$x]).html"; } #give me a message to let me know the script has completed. echo "Done!" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload