It sounds like what you really want to do is pull just the table parts out of
the return string of convertto-html. This way you can add the starting and
ending tags back as well as being able to input new info between the tables.
Since the output of that cmdlet always has the same start and closing tags
you can just strip them with the lengths of those values.... i.e.
function extractTable {
param($message)
return $message.Substring(205,$message.Length - 221)
}
#so to put it to use you could do:
$first = extractTable (dir |ConvertTo-Html|out-string)
$second = extractTable (Get-Process |ConvertTo-Html|Out-String)
#You could modify the below with the static text rather than getting it
dynamically since it never changes
$head = $first.Substring(0,207)
$tail = $first.Substring($first.Length-17)
$final = $head + $first
$final += "<H1>STARTING MY GET-PROCESS HERE, SUCKAH</H1>"
$final += $second + $tail
$final |out-file test.html
& .\test.html
The above will work to concatenate multiple out-html cmds with comments...
so in your example you would do:
foreach server {
$final += "<H1>$server</H1>"
$final += "<P>$comment</P>"
$final += ExtractTable (Checkservices |out-html|out-file)
$final += "<P>$comment2</P>
$final += ExtractTable (checkqueue|out-htmlout-string)
#etc...
}
"djmulls" wrote:
> Hi Guys,
>
> Struggling to figure this one out, and it has been bugging me for a
> while.
>
> I have written a script which checks services, logs, event viewer
> entries, queues, etc and then writes the necessary results to screen.
> Works perfectly.
>
> I want to change this so it's written to a HTML file, but because I am
> not using just one command to perform this action and I want to add
> comments inbetween, such as server names I am having no joy in terms
> of formatting. Or I lose the comments, etc
>
> So doing one command in a loop and outputing the contents to HTML is
> no problem.
> Eg: foreach server check services | convertto-html ...
>
> Doing a loop for each server with multiple checks and then looping
> back to the next server doesn't work
> Eg:
> foreach server
> Write server name
> Write comment
> Check services
> Write comment
> Check queue
> Write comment
> Check event log
> Etc
>
> Basically I need a way to continually append comments to the body of a
> HTML page.
>
> The only way so far I have managed to do it, is to output everything
> to a txt file and then convert that to a HTML file, but that loses
> formatting and gets very messy.
>
> Any ideas?
>
> Thanks
> David
> .
>


