output in HTML in Powershell

[cmdletbinding()]
param
(
[Parameter(Position=0,ValuefromPipeline=$true)]
[string[]$ComputerName = $env:COMPUTERNAME
)
cluster node /status

If ($? -eq "True") {

$cluster = cluster node /status

$a = @'
<style type='text/css'> .nxn-ret-table{width:100%; border-collapse:collapse; font-family: Arial;} /* Define the background color for all the ODD background rows */ .nxn-ret-table tr:nth-child(odd){ background: #DAE0E1;} /* Define the background color for all the EVEN background rows */ .nxn-ret-table tr:nth-child(even){background: #f7f7f7; } pre { font-family: Arial; overflow: auto;} </style>

'@

$cluster | ConvertTo-Html -As List -Head $a -body "<H2>Cluster Status</H2>" | Out-File -FilePath C:\tmp\user.txt
Get-Content 'C:\tmp\user.txt' | Foreach-Object {$_ -replace '<table>', ("<table class='nxn-ret-table'>")} | Foreach-Object {$_ -replace '^<html.*$', ("<html>")} | Set-Content 'C:\tmp\user1.txt'

cat C:\tmp\user1.txt
}
else {Write-Host "<html><h1>Cluster is not configured on $ComputerName</h1></html>"}

when i run the above script .,output comes like

Node           Node ID Status

-------------- ------- ---------------------

WSOMQAVDCI02         1 Up

wsomqavdci01         2 Up

But when trying to get the output in HTML.it does not work.

Can you please help in getting the out in HTML format
Suresh KumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
It won't trivially convert to HTML because the command you're using is returning a simple string.

Find the PowerShell alternative for "cluster node /status" and you can use ConvertTo-Html on it. That might well be something as simple as Get-ClusterNode.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oBdACommented:
Try it like this:
[CmdletBinding()]
Param(
	[Parameter(Position=0,ValuefromPipeline=$true)]
	[string[]]$ComputerName = $env:COMPUTERNAME
)
$Head = @'
<style type='text/css'> .nxn-ret-table{width:100%; border-collapse:collapse; font-family: Arial;} /* Define the background color for all the ODD background rows */ .nxn-ret-table tr:nth-child(odd){ background: #DAE0E1;} /* Define the background color for all the EVEN background rows */ .nxn-ret-table tr:nth-child(even){background: #f7f7f7; } pre { font-family: Arial; overflow: auto;} </style>

'@
Try {
	Import-Module FailoverClusters -ErrorAction Stop
	Get-ClusterNode -ErrorAction Stop |
		Select-Object Name, ID, State |
		ConvertTo-Html -As List -Head $Head -body "<H2>Cluster Status</H2>" |
		Foreach-Object {$_ -replace '<table>', ("<table class='nxn-ret-table'>")} |
		Foreach-Object {$_ -replace '^<html.*$', ("<html>")} |
		Set-Content 'C:\tmp\user1.txt'
		Get-Content -Path 'C:\tmp\user1.txt'
} Catch {
	Write-Host "<html><h1>Cluster is not configured on $ComputerName</h1></html>"
}

Open in new window

0
Chris DentPowerShell DeveloperCommented:
It'll need a handler for a remote call to make sense of the ComputerName parameter. The second replace is weird and can probably just go.
0
oBdACommented:
The remote support wasn't used in the original (and "ValueFromPipeline=$tTrue" is rather pointless as well, since there's no Process {} block.), so I think that's just a "copy and paste" from a script template.
It would need the cluster name in this case, though ("Get-ClusterNode -Cluster <ClusterName> -ErrorAction Stop"), not a node name.
The second "replace" removes the XML namespace that ConvertTo-Html adds to the <html> tag (<html xmlns="http://www.w3.org/1999/xhtml">).
0
Chris DentPowerShell DeveloperCommented:
I stand by "weird" ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.